How to replace all duplicate substrings one by one with diffrent -2 specified words in a string

Dear All,
I want to replace a string like below example
Example : input string is : Hi Uipath Hello Uipath Hey Uipath bye uipath. i want output like : Hi 1 Hello 2 Hey 3 bye 4.
I will be very thank full if some suggest me.

Split string in Array using uipath as seperator
Then you have 4 parts
Next loop with counter

@Prashant_Rajput
unfortunately not done with an oneliner, but is working and ignores the cases:

grafik

with: Regex.Matches(strText,"UiPath",RegexOptions.IgnoreCase) the relevant parts are found
with: New Regex(item.Value).Replace(strText,(idx + 1).toString,1) the found text is replaced by counter No

Find demo XAML here:
ReplaceOccurenceStringWithCounter.xaml (6.1 KB)

3 Likes

Thank you so much. It worked @ppr

Instead of changing “Uipath” to 1/2/3. Is it possible to change it to UipathA/UipathB/UipathC? If yes what will be the line of code?