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: 
kyleabaker
Visitor

Strip out special characters from a string

I think the title is pretty self explanatory, but I'm hoping someone has a much better idea (both performance and code maintainability-wise) to remove characters from a string.

What I'm looking to do is take any string and remove any characters other than A-Z, 0-9 or whitespace. Ex. "Hello: World!" would become "Hello World". The only approach that I can think of at the moment is to have a stack of ReplaceAll()'s, but I was wondering if there was a better approach or if there's a Regex approach that I've not thought of yet.

Thanks!
0 Kudos
2 REPLIES 2
RokuMarkn
Visitor

Re: Strip out special characters from a string


regex = CreateObject("roRegex", "[^a-zA-Z0-9\s]", "")
clean = regex.ReplaceAll(dirty, "")


--Mark
0 Kudos
kyleabaker
Visitor

Re: Strip out special characters from a string

Thanks Mark! That was exactly what I was looking for!
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.