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: 
rsromeo
Channel Surfer

REPLACE SUBSTRING FUNCTION

Hi -

Does anyone know if Brightscript has a replace function to replace s substring of text?

for example, I would like to do something like this...

string = "this is a file name.mp4"
newstring = replace(string," ","%20")
0 Kudos
4 REPLIES 4
evilmax17
Visitor

Re: REPLACE SUBSTRING FUNCTION

You can find it in generalUtils.brs in the videoplayer example.

'******************************************************
'Replace substrings in a string. Return new string
'******************************************************
Function strReplace(basestr As String, oldsub As String, newsub As String) As String
newstr = ""

i = 1
while i <= Len(basestr)
x = Instr(i, basestr, oldsub)
if x = 0 then
newstr = newstr + Mid(basestr, i)
exit while
endif

if x > i then
newstr = newstr + Mid(basestr, i, x-i)
i = x
endif

newstr = newstr + newsub
i = i + Len(oldsub)
end while

return newstr
End Function
My Roku Channels:
Viddler - viddler.com
Tested Fan - tested.com | Jamie & Adam
This is my next - theverge.com
1080p Showcase - RIP
Whiskey Media - RIP
======================
http://www.binarymoustache.com
0 Kudos
evilmax17
Visitor

Re: REPLACE SUBSTRING FUNCTION

Also, for your specific example, you might be interested in roUrlTransfer.Escape( string ).

String Escape(String text)
URL encode the specified string using CURL.
My Roku Channels:
Viddler - viddler.com
Tested Fan - tested.com | Jamie & Adam
This is my next - theverge.com
1080p Showcase - RIP
Whiskey Media - RIP
======================
http://www.binarymoustache.com
0 Kudos
TheEndless
Channel Surfer

Re: REPLACE SUBSTRING FUNCTION

"evilmax17" wrote:
Also, for your specific example, you might be interested in roUrlTransfer.Escape( string ).

String Escape(String text)
URL encode the specified string using CURL.

And/Or UrlEncode()...
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
rsromeo
Channel Surfer

Re: REPLACE SUBSTRING FUNCTION

thanks guys
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.