Update specific position in a String variable


#1

I am new to UIPath Automation. Looking for assistance on the below query.

I have a string variable of 100 chars and wanted update specific position(say Start Position: 11, Length:10) with the derived value.

Tried using the combination of keywords substring and replace. But nothing worked.

InputString = "C1010111COxxxxxxxxxxDANIEL MICHELLE ON 68GS63"
Derived value = “HOUSEHOLD”

Want xxxxxxxxxx to be updated with Derived value.

OutputString = “C1010111COHOUSEHOLD DANIEL MICHELLE ON 68GS63”


#2

Hi @muthuppm,

Try the following Command,
InputString.Replace(InputString.substring(10,10),Derived value)
Regards,


#3

Thanks for update Hemanth.

If my InputString happens to be “C1010111COxxxxxxxxxxDANIEL MICHELLE ON 68GS63xxxxxxxxxx”, then Output String will become “C1010111COHOUSEHOLDDANIEL MICHELLE ON 68GS63HOUSEHOLD”.

The second instance of xxxxxxxxxx should not be updated with HOUSEHOLD


#4

Okey @muthuppm,

Then we go with Regex
regexVar=new regex(InputString.subString(10,10))
regexVar.replace(InputString,Derived Value,1)

Its working fine for me.
Regards,


#5

@muthuppm

If your input string will always have 10 X’s then you can use like this.

Inputstring.Replace(“xxxxxxxxxx”,Derived Value)

Regards,
Mahesh