Find and replace in ActionScript

Here i have given two functions

  • Find – Checks whether the string holder contains the word and returns true or false
  • FindAndReplace – Checks for the string and replace with the new word provided.

var Str=“i love blogging”
var
out=Find(Str,“love”)
trace
(“result —>” +out)
var
out1=FindAndReplace(Str,“love”,“hate”)
trace
(“result1 —->”+out1)

function Find(SourceStr, FindString) :Boolean
{
var NArray=SourceStr.split(FindString)
if(NArray.length==2)
return true
else

return false
}

function FindAndReplace(SourceString, FindString,ReplaceString) :String
{
var SplitArray=SourceString.split(FindString)
var Result=SplitArray.join(ReplaceString)
return
Result;
}