AS3 – Search & Replace a Word


In a project I was working on recently there was some information coming back from the database that I was displaying in a textfield. I didnt have any control of the text stored in the database and it was saying to ‘click the button above…’ but in this new interface we were designing, the button was below this textfield. I wrote a little function that replaced the word ‘above’ with ‘below’. Code after the break.

1
2
3
4
5
private function searchAndReplace(str, searchfor, replacement):String {
	var temparray:Array = str.split(searchfor);
	str = temparray.join(replacement);
	return (str);
}
Spread the Good Word:
  • Digg
  • del.icio.us
  • Facebook
  • NewsVine
  • StumbleUpon

,

  1. #1 by jacko on July 29, 2010 - 6:36 am

    thnx just wat i needed :D

(will not be published)

Switch to our mobile site