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: 

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
0 Kudos
2 REPLIES 2
TheEndless
Channel Surfer

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)
0 Kudos
RokuChris
Roku Employee
Roku Employee

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()
0 Kudos