Solved

Recursive Find / Replace

Posted on 2008-10-04
3
399 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

763 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