Adobe-Flex-CS3-48x48Heb je dat ook wel eens ? Dat je in een string iets wilt wijzigen in Adobe Flex en Actionscript  maar … hoe ?

Tja tijdens diverse werkzaamheden bij NL for Business (NL4B) had ik dat ook. Waarom bestaat er geen goede replace in Adobe Flex.

Nu wel ;-)

Ik heb de volgende code gemaakt, deels vanuit andere code sites.

Zet de volgende code binnen je AS3 script of tussen <mx:script.

private function str_replace( replace_with:String,
replace:String,
original:String ) : String {
      var array:Array = original.split(replace);
      return array.join(replace_with);
  }

Hoe te gebruiken ? Heel simpel, replace_with is waarmee je het wilt vervangen, replace is het deel dat je wilt verangen, original… is dus het origineel.

var newString:String = str_replace("", " ", postal);

dus….

original = “The quick brown fox jumps over the lazy dog”;

replace_with = “yellow”;

replace = “brown”;

wordt : ”The quick yellow fox jumps over the lazy dog”;

About the author

Theo van der Sluijs Theo van der Sluijs (1975) is Lead Developer at Unitrust BV. He is also creator of "I Am Bored So I blog" / Gebruikmaar.nl / vanderSluijs.nl. He is a member of the Board of the Dutch Flex Usergroup and Goesweb.net. With his quote "Never Give Up, Never Surrender" (Actually stolen from Galaxy Quest) he fights his way through the day. Connect with him on Twitter.

VN:F [1.9.3_1094]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)

Leave a Reply

QR Code
Donate

Like the information on my site? Please donate for a cup of coffee, or give a bit more for a cappuccino.

Twitter
Backlinks
Get Adobe Flash playerPlugin by wpburn.com wordpress themes