Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
brocker
Visitor

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
0 Kudos
5 REPLIES 5
destruk
Streaming Star

Re: To String Method?

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.
0 Kudos
brocker
Visitor

Re: To String Method?

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 <value>.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
0 Kudos
TheEndless
Channel Surfer

Re: To String Method?

"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
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
brocker
Visitor

Re: To String Method?

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! 🙂

Ermm.. destruk just showed you how to do that...
0 Kudos
mushiidoger
Visitor

Re: To String Method?

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
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.