Is there any kind of all encompassing “ToString” method with BrightScript? I have found a couple, but they seem to be specific to a cast such as Integer to String. My issue is I don’t know what the type is for sure, so I keep getting “type mismatch” errors when trying to use one in a string compare.
Has anyone written a all catching ToString method or is there one built in that I am not seeing?
I’m actually trying to do a conversion, not check what it is. I was hoping there was a built in method (like most other languages) that has a simple .ToString().
But, maybe I’m thinking a bit too big, is there a way to determine what type a value is, and return that? So if I had “Foo”, could I print what type of a value Foo is? At least this way I could walk a If Else tree and convert using one of the built in BrightScript methods.
“brocker” wrote:
But, maybe I’m thinking a bit too big, is there a way to determine what type a value is, and return that? So if I had “Foo”, could I print what type of a value Foo is? At least this way I could walk a If Else tree and convert using one of the built in BrightScript methods.
Ermm.. destruk just showed you how to do that…
How about something like this?
Function ToString(variable As Dynamic) As String
If Type(variable) = "roInt" Or Type(variable) = "roInteger" Or Type(variable) = "roFloat" Or Type(variable) = "Float" Then
Return Str(variable).Trim()
Else If Type(variable) = "roBoolean" Or Type(variable) = "Boolean" Then
If variable = True Then
Return "True"
End If
Return "False"
Else If Type(variable) = "roString" Or Type(variable) = "String" Then
Return variable
Else
Return Type(variable)
End If
End Function