as3 blog

thoughts on actionscript 3 development

   Mar 26

search and replace in strings

it’s been a while since i needed to do this. nice technique is to use ‘split’ to break the string into an array using the split’s arguments as the deliminator then ‘join’ to stick is back together using joins arg to put between each element. the effect is a search and replace

var str:String = "this is a string with some spaces that need replacing with _"
str = str.split(" ").join("_");
// simple :)
									

You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

One Comment

  1. Adam says:

    I will remember this one. I just know it’s going to come in useful when I least expect it.

Leave a Reply

Your email address will not be published. Required fields are marked *

* 4+6=?

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>