I created a function to replace a string in a string

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
Posts: 1273
Joined: 23 Nov 2010
Has thanked: 721 times
Been thanked: 222 times

I created a function to replace a string in a string

Postby arjfca » 30 Dec 2015


I submitted a String replace function to replace one or many charracters in a string

You could see it there

ReplaceStr(Eur.Usd,".","_"); = "Eur_Usd"
Original String: Eur.Usd
To be replace: "."
To be replace by:"_"

ReplaceStr("Hello, my name is Martin","Martin","Paul") = "Hello my name is Paul"

//ReplaceSTR will replace a series of characters with the new one

//By Martin Theriault December 29 2015

Lookfor (String),
ReplaceBy (String);


LengthInput (0),
Length_ReplaceBy (0),
Length_LookFor (0),
Temp_Length (0),
TempString ("");

LengthInput = strlen(InputString);
Length_Lookfor = strlen(Lookfor);
Length_ReplaceBy = StrLen(ReplaceBy);

Position = Instr(InputString,LookFor);
TempString =LeftStr(inputString,(position-1 ))+ replaceby;
Temp_Length = StrLen(TempString);
TempString = tempstring + RightStr(InputString, (LengthInput -(position + length_lookfor -1)));

replacestr = Tempstring;
print ("exit>: , ", replacestr);

Return to “User Contributed Studies and Indicator Library”