Hi Replace (String,'5','6') , function i am using for replace all occurrences of '5' in the string , but here i want a functionality like its only replace its last occurrence, not all
how to achieve that
like in java we have lstIndexof(), First index of kind of
Hi Priya,
Susheel has mostly given you an answer that works, though I wouldn't use Replace() if there's only a single character to replace and you know it's position.
Like Susheel showed, you can use the built-in Index() function with searchFromEnd True to find the last occurence of a "5". Once you have that position you can use two Substr() functions to get the part before the returned index, and the part after it, and concatenate that. Something like:
Substr(MyVar, 0, Index) + "6" + Substr(MyVar, Index + 1, 1000)
(where 1000 is some arbitrarily large number).
Hi @Priya Naveen,
Use this expression.
Name =M5a5n5s5u5r5885r3
Output : M5a5n5s5u5r5886r3
Substr(Name,0,Index(Name,"5",searchFromEnd:True))+Replace(Substr(Name,Index(Name,"5",searchFromEnd:True),Length(Name)-1),"5","6")
I also attached OML file.Hope this will help you.
Kind regards,
Susheel Yadav
Hi @Priya Naveen
you Can used this function to Achieve your Requirement.
Replace(Name,Substr(Name,Index(Name,"5",searchFromEnd:True)-1,Index(Name,"5",searchFromEnd:True)),"6")
I have Attached oml file so please go through this:
Thanks
Md Mansur
Sadly this is not available in OutSystems. You need to loop it.
Or you can convert string in to character list and use listfiter and join output again.
You can use javascript to replace below is the syntax:
let var1 = "a5b5ccc5d";
let var2 = var1.replace(/5(?!.*5)/, '6');
$parameters.Out1 = newString;
Hope this helps you!!
Regards,
Rajat
i want this feature in the server action side
By using client action you can also use JavaScript (regular expression). Check the following example
https://personal-u1aragiz.outsystemscloud.com/Testa/JSRegularExpressionTest?_ts=638592486105082121
As previously told that you need to split the string so it will we converted in list and than you can filter the list and join list again. Like below
https://personal-u1aragiz.outsystemscloud.com/Testa/JSRegularExpressionTest?_ts=638592494047422045
I added server side button as well you can check that if its work for you. Attaching solution as well.
This is a very inefficient and bad way to do it.
Sorry I got it wrong. I understood the problem statement totally wrong.