The reason I didn't want to use regex is in the real program the string to replace is variable.
I finally broke down and used a regex. Paul --- In [email protected], "Tracy Spratt" <[EMAIL PROTECTED]> wrote: > > And in case he really does not want to use regular expressions, there is > always the Array split/join approach. > > > > public static function replace(sString:String, sFind:String, > sReplace:String):String > > { > > return sString.split( sFind ).join( sReplace ); > > } > > > > Tracy > > > > ________________________________ > > From: [email protected] [mailto:[EMAIL PROTECTED] On > Behalf Of Guy Morton > Sent: Friday, August 15, 2008 7:06 PM > To: [email protected] > Subject: Re: [flexcoders] global replace with strings > > > > I think the point is he's not aware that the way to do what he wants is > to create a RegEx with the g flag. eg > > > > var strTest:String = "This is a test string"; > > var reggy:RegExp = new RegExp("t", "g"); > > trace(strTest.replace(reggy,"s")); > > > > >This is a sess ssring > > > > HTH > > > > On 16/08/2008, at 3:23 AM, Alex Harui wrote: > > > > > > > > Why can't you use RegEx? A much slower way would be something like: > > > > var inString:String = strTest; > > while (true)) > > { > > var outString:String; > > outString = inString.replace("t", "s"); > > if (outString == inString) > > break; > > inString = outString; > > } > > > > ________________________________ > > From: [email protected] [mailto:[EMAIL PROTECTED] On > Behalf Of aceoohay > Sent: Friday, August 15, 2008 9:31 AM > To: [email protected] > Subject: [flexcoders] global replace with strings > > > > Is there a way of replacing all occurences of one string with another > without using regular expressions? > > var strTest = "this is a test" > > trace strTest.replace("t","s"); > > returns "shis is a test" I want "shis is a sess". > > Paul >

