Solved

Recursive Find / Replace

Posted on 2008-10-04
3
398 Views
Last Modified: 2010-04-21
Does anyone have a recursive Find/Replace function for ActionScript 3?  I've searched and searched the all-knowing Google and have come up with nothing useful, and it seems the built in replace function only replaces the first match.
0
Comment
Question by:anoyes
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
Antonio Estrada earned 250 total points
ID: 22642209
Here you go:

<code>

-V
var myString:String = "Ahem... hello there, what's up? hello again";
var myNewString:String = strReplace(myString,"hello","hi");
trace(myNewString);
 
function strReplace(str:String,lookUp:String,replaceWith:String):String {
	var retVal:String;
	var startStr:String;
	var endStr:String;
	var index:Number;
	retVal = str;
	index = retVal.indexOf(lookUp);
	if(index!=-1) {
		while(index!=-1) {
			startStr = retVal.substr(0,index);
			endStr = retVal.substr(index+lookUp.length,retVal.length);
			retVal = startStr + replaceWith + endStr;
			index = retVal.indexOf(lookUp);
		}
	} 
	return retVal;
}

Open in new window

0
 
LVL 16

Author Closing Comment

by:anoyes
ID: 31503065
Excellent!  This has been causing such a problem for me.  Thanks!
0
 
LVL 18

Expert Comment

by:Antonio Estrada
ID: 22642294
Glad to help :)

-V
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Embedding Flash App/Movie on Website 3 502
HTML 5 or Flash 7 489
SWF capture the time on the Video 3 225
Streaming to Flash Media Server with ffmpeg, crashes on start 3 260
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question