ajporterfield
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2012
09:43 PM
PHP explode/implode Brightscript Equivalents
PHP has many useful built-in array functions that I miss when developing Roku channels with Brightscript. So, I decided to write (and share) a couple equivalents in Brightscript. Please feel free to use these as is and/or comment on how your versions are better/more efficient than what I've posted:)
function explode(delimeter, string)
result = []
position1 = 1
position2 = Instr(position1, string, delimeter)
delimeterLen = Len(delimeter)
stringLen = Len(string)
while position2 <> 0
result.Push(Mid(string, position1, position2 - position1))
position1 = position2 + delimeterLen
position2 = Instr(position1, string, delimeter)
end while
if position1 <= stringLen
result.Push(Mid(string, position1))
else if position1 - 1 = stringLen
result.Push("")
end if
return result
end function
function implode(glue, pieces)
result = ""
for each piece in pieces
if result <> ""
result = result + glue
end if
result = result + piece
end for
return result
end function
2 REPLIES 2

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2012
09:58 PM
Re: PHP explode/implode Brightscript Equivalents
I believe the Tokenize() method on a string will do what your explode function does.
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)


Roku Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2012
10:48 PM
Re: PHP explode/implode Brightscript Equivalents
"TheEndless" wrote:
I believe the Tokenize() method on a string will do what your explode function does.
You could also try roRegEx::Split()