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!
arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

I created a function to replace a string in a string

Postby arjfca » 30 Dec 2015

Hello

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

You could see it there
viewtopic.php?f=5&t=49295#p118970

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

Input:
InputString(String),
Lookfor (String),
ReplaceBy (String);

Var:

Position(-1),
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”