Sheri
(Sheri)
July 29, 2019, 10:09pm
1
Hi!
How would I go about replacing only the last comma in a string and changing it to “and”?
For example:
Neebs, Appsro, Thick, Dora, Simon
I would want to replace only the comma between “Dora” and “Simon” and change it to the word “and”, so the string becomes:
Neebs, Appsro, Thick, Dora and Simon.
Appreciate any feedback, thanks!
1 Like
mcicca
(Marco)
July 29, 2019, 10:36pm
2
Hi @Sheri ,
You should be able to use regex replacing to do this!
See below:
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET.
In UiPath, you would need to have the Regular Expressions namespace/import and could then use Assign as such:
strVariable = Regex.Replace(yourString, “(?:,)([^,]+)$”, " and\1").ToString
Note that there is an extra space before the and in the replace.
Let me know if you have any more questions
Yoichi
(Yoichi)
July 29, 2019, 11:35pm
3
Hi,
You can get the position of last comma with LastIndexOf method.
intIndex = strData.LastIndexOf(",")
Then, you can remove it and insert " and "
strData = strData.Remove(intIndex,1).Insert(intIndex," and ")
Regards,
Yoichi
3 Likes
system
(system)
Closed
August 1, 2019, 11:35pm
4
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.