58
Views
11
Comments
Solved
Replace (String,'5','6')  , function i am using for replace all occurrences of  '5' i

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

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

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).

2026-03-06 17-10-46
Susheel Yadav
Solution

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


ReplaceFinal-SY.oml
UserImage.jpg
Md Mansur

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


ReplaceFinal.oml
2022-12-30 07-28-09
Navneet Garg

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.


2020-07-21 19-28-50
Rajat Agrawal
Champion

Hi @Priya Naveen,

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

2024-06-03 11-04-24
Priya Naveen

i want this feature in the server action side

2022-12-30 07-28-09
Navneet Garg

By using client action you can also use JavaScript (regular expression). Check the following example

https://personal-u1aragiz.outsystemscloud.com/Testa/JSRegularExpressionTest?_ts=638592486105082121

2024-06-03 11-04-24
Priya Naveen

i want this feature in the server action side

2022-12-30 07-28-09
Navneet Garg

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.


Testa.oml
2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

This is a very inefficient and bad way to do it.

2022-12-30 07-28-09
Navneet Garg

Sorry I got it wrong. I understood the problem statement totally wrong.

2026-03-06 17-10-46
Susheel Yadav
Solution

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


ReplaceFinal-SY.oml
2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

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).

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.