Home > Flash > Text Replace

Text Replace

Some days before I was trying to replace specific character or a set of characters from a text message, using actionscript. You can use ‘ replaceString(arg…)’ for that.

 var stringData:String = “Text Replace”;

var strReplaceThis:String = “Replace”;

var strReplaceBy:String = “Changed”; 

var resultString:String = replaceString(stringData, strReplaceThis, strReplaceBy); 

trace(“String Data : ” + stringData)

trace(“Result String : ” + resultString) 

function replaceString(stringData, strReplaceThis, strReplaceBy)

{

var str = stringData

var strReplaceThisLength = strReplaceThis.length;

var strReplaceByLength = strReplaceBy.length;

var strPars = str.indexOf(strReplaceThis);

while (strPars != -1)

{

str = str.substr(0,strPars) + strReplaceBy + str.substr(strPars + strReplaceThisLength);

strPars = str.indexOf(strReplaceThis, strPars + strReplaceByLength);

}

return str; 

}

Advertisements
  1. Nishita
    February 26, 2009 at 6:06 PM

    Hi, Bharat,
    Regarding your Text Replace function , it’s really very helpful during development of so many Flash Application.

    Thanks Buddy.

  2. Priya
    May 23, 2009 at 9:45 PM

    Hi Bharat,

    Your this post will help me a lot in my work. Thanks for that.

    It’s nice post

    I want to know certain things regarding red5 development. I know that you are working with FMS and Red5 also.

    I had send you an mail for that.

    Thanks
    Priya

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: