Solved

Recursive Find / Replace

Posted on 2008-10-04
3
396 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
Comment Utility
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
Comment Utility
Excellent!  This has been causing such a problem for me.  Thanks!
0
 
LVL 18

Expert Comment

by:Antonio Estrada
Comment Utility
Glad to help :)

-V
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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 …
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,…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
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.

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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now