brocker
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2011
01:23 PM
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
Has anyone written a all catching ToString method or is there one built in that I am not seeing?
Thanks
Bud
5 REPLIES 5
destruk
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2011
03:17 PM
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.
If type(variablename)="roInt" or type(variablename)="roInteger" Then
Basically any generic routine would be doing that already within it.
brocker
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2011
03:32 PM
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
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
![TheEndless TheEndless](http://roku.permanence.com/images/sandman_endless_100x100.gif)
TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2011
03:46 PM
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)
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
brocker
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2011
03:53 PM
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! 🙂
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...
mushiidoger
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2013
02:56 AM
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
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