To String Method?

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?

Thanks
Bud

You could check the variable first.
If type(variablename)=“roInt” or type(variablename)=“roInteger” Then

Basically any generic routine would be doing that already within it.

Thanks destruk!

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.

Just a thought

Thanks
Bud

“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

Thanks endless,

That works really great! Exactly what I was looking for, thank you as always.

Best!
Bud

PS: Please be nice, I’m learning, I don’t have your experience so things like this may fly over my head, I’m trying tho! :slightly_smiling_face:

Ermm.. destruk just showed you how to do that…

hey all
i request to url
and i want to check if i get xml program take to appMain function and i get any string i jump to error()

how to check or how to write the code