"joetesta" wrote:
Is there an easy way to turn the String into an roString...?
Box("String value")
"belltown" wrote:Box("String value")
Id = myAssocArray.Id
Id = Id.ToStr()
? "Got the Id: "; Id; " - Id type is "; type(Id)
Id = box(Id)
? "Now Id type is "; type(Id)
if (type(i) = type(value) OR ((type(i) = "String" OR type(i) = "roString") AND (type(value) = "String" OR type(value) = "roString")))
AND i = value then return TRUE
if getInterface(x, "ifString") <> invalid then ...and it will cover all cases, see viewtopic.php?f=34&t=67449 for discussion.
"joetesta" wrote:
Unfortunately belltown's solution doesn't work"belltown" wrote:Box("String value")
Id = myAssocArray.Id
Id = Id.ToStr()
? "Got the Id: "; Id; " - Id type is "; type(Id)
Id = box(Id)
? "Now Id type is "; type(Id)
output:
Got the Id: 82547 - Id type is String
Now Id type is String
myAssocArray = {Id: 42}
BrightScript Debugger> Id = myAssocArray.Id
BrightScript Debugger> Id = Id.ToStr()
BrightScript Debugger> ? "Got the Id: "; Id; " - Id type is "; type(Id)
Got the Id: 42 - Id type is String
BrightScript Debugger> Id = box(Id)
BrightScript Debugger> var
global rotINTERFACE:ifGlobal
m roAssociativeArray refcnt=2 count:0
id roString (2.1 was String) refcnt=1 val:"42"
myassocarray roAssociativeArray refcnt=1 count:1
BrightScript Debugger> ? "Now Id type is "; type(Id)
Now Id type is String
BrightScript Debugger> ? "The Id type really is "; type(Id, 3)
The Id type really is roString
"EnTerr" wrote:
But what are you even trying to accomplish? If you can state your problem more generally, we can probably suggest a better/faster solution with roAAs
"belltown" wrote:
To guarantee that the correct BrightScript 3 string type is returned, you need to add the "3" parameter:
"belltown" wrote:
Or check that Type(Id) is a "String" or "roString"
"joetesta" wrote:"belltown" wrote:
Or check that Type(Id) is a "String" or "roString"
Yep that's what I did with my long "if" line, but EnTerr didn't like it - hey, it works! 🙂
BrightScript Debugger> arr = []: hash = {}: for i=1 to 1000: s = str(i): arr.push(s): hash[s] = i-1: nextSo far, so good?
BrightScript Debugger> find1 = function(arr, el): i=0: while i < arr.count() and arr[i] <> el: i+=1: end while: return i: end function
BrightScript Debugger> ? find1(arr, " 7"), find1(arr, "7")
6 1000
BrightScript Debugger> find2 = function(hash, el): return hash[el]: end function
BrightScript Debugger> ? find2(hash, " 7"), find2(hash, "7")
6 invalid
BrightScript Debugger> ti = createObject("roTimeSpan")We just demonstrated rummaging in linear fashion being 100x slower.
BrightScript Debugger> ti.mark(): for j=1 to 1000: find1(arr, str(i)): next: ? ti.totalMilliSeconds()
5246
BrightScript Debugger> ti.mark(): for j=1 to 1000: find2(hash, str(i)): next: ? ti.totalMilliSeconds()
45