The Burned Out Hippy - Hugging Flash into Submission

Replacing white space in a string

posted by The Hippy in Actionscript 3, Useful code bits

A handy little tip, if all you need to do is rip out spaces in a string don’t bother with using slice(), use regex instead. Copy the following line of code and replace ‘-’ with whatever you need to replace the space with…

yourString = yourString.replace(/\s+/g, '-');

So for example, if yourString=”blah blah blah”, it will now become “blah-blah-blah”. This is especially useful for amending URLs.

Happy new year!

Post to Twitter Post to Facebook Post to StumbleUpon Post to Digg

Removing non alpha-numeric characters from a string

posted by The Hippy in Actionscript 3, Useful code bits

Need to strip slashes, back slashes, hyphens and other symbols from a string? Looked at regex and cried “why? why? why?” at the moon repeatedly? Considered throwing your monitor out of the window? No worries. Here’s your solution:

var r:RegExp = new RegExp(/[^a-zA-Z 0-9]+/g) ;
yourString = yourString.replace(r, "");

Robert’s your father’s brother.

Post to Twitter Post to Facebook Post to StumbleUpon Post to Digg

Recent Posts
Recent Comments
About Us
YAS: Grt. This really helped. Thanxxxxxxx........
Derek Lancaster: Mark and Hippy, Thanks very much. Genius. I have just had a download from Orange...
Graham: I hate changing my registry, on the advice of 'the internet'. But this completely fix...
Toby: Genius, thank you....

This site is the playground of the The Burned Out Hippy, head honcho of the web design and multimedia company Plagro. It serves no other purpose than to act as a place where I can store my most recent Flash ActionScript experiments. However, I will be posting code whenever an experiment is complete so that you can have a play with it yourselves.

Read more about The Burned Out Hippy...