Solved

Recursive Find / Replace

Posted on 2008-10-04
3
401 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

630 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