How to replace string by index position

Hi I need to replace a string by it’s index position

Str1 = 0110000505

i want to replace 05 with 99 when i use replace functions it is replacing it as 0110009999 but i want to replace only last part of 05 so the expected output will be as 0110000599.

Any Suggestions thanks in advance.

You should be able to do that with Substring:

Str1 = Str1.Substring(0, Str1.Length-2) + "99"

See this post to learn about string manipulation:

2 Likes

Thanks for your response.

Your solution works if the replacing numbers are at the end what if i want to replace first part of “05” so the output would look like

01100009905

Then you will need to use IndexOf also to find the position of “05” so you can get the parts before and after “05”.

pos = Str1.IndexOf("05")
Str1 = Str1.Substring(0, pos) + "99" + Str1.Substring(pos+2)

pos is of type Int32

Hello @sathwik19

Just throwing another alternative out there from @ptrobot

You could use a Regex ‘Replace’ activity.

Scenario 1

Scenario 2

Hopefully you get the right solution for your needs :blush:

1 Like