UiPath enter a value in a particular index in string

Suppose I have a string “ABCD”

I want to replace the value D with something else
The value D is dynamic

Is there a way to replace D with the value without using .Replace function ?
The string can also be “ABCDDD” . In case I use .Replace D it will replace D from all index. Howwever our goal is the replace “D” only from index 3

One of many options:
grafik

Hey @Ritaman_Baral ,

Assign
myString = “ABCDDD”

Assign
replacement = “H”

Assign
modifiedString = myString.Substring(0, 3) + replacement + myString.Substring(4)

image

HAPPY AUTOMATION!!

Hi @Ritaman_Baral

Can you try the below

Input="ABCDDDD"
If(Input.Length > 3, Input.Substring(0, 3) & "X" & Input.Substring(4), Input)

Input="ABCD"
If(Input.Length > 3, Input.Substring(0, 3) & "X" & Input.Substring(4), Input)

Cheers!!

Hi @Ritaman_Baral

Input="ABCD"
Message Box-> Input.Remove(3, 1).Insert(3, "X")

Input="ABCDDD"
Message Box-> If(Input.Length > 3, Input.Substring(0, 3) & "X" & Input.Substring(4), Input)

You can use any of the two syntaxes.

Hope it helps!!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.