String manipulation with constant string length

Hi everyone this is my first post, need help with string manipulation as i am working in terminal sessions its getting tricky.

i am getting a string with value (“29/HCGS/416813/001/PN”)
i need to manipulate it so that the output should have “S”(constant) for every string value including SPACE " " and the given string. but the tricky part is only one of the “/” infront of “001” in string should be replaced by SPACE " ".
The length of string gonna be constant(21).
required final output should be like (“S 29/HCGS/416813 001/PN”)


Hi @Manuvidesh Welcome to UiPath Community,

If the string format and length is standard, then you can use

string str = “29/HCGS/416813/001/PN”;
str = "S " + str.Remove(14, 1).Insert(14, " ");

Note : the 14 was the index of “/” in string.

Otherwise you can use RegEx by finding 3rd occurrence and replacing it by Space.

Or use the String.ReplaceAt() method by using indexes.

Hope you will get sollutions.

Michael Udhaya

1 Like

Hey @Manuvidesh

You can try this also even length will vary then also it will work.

String Str=  "29/HCGS/416813/001/PN";

Int32 SecondLastIndexOfChar = Str.LastIndexOf("/",Str.LastIndexOf("/")-1);

String Result = "S "+Str.Remove(SecondLastIndexOfChar,1).Insert(SecondLastIndexOfChar," ")

WriteLine  - Result  // Output - S 29/HCGS/416813 001/PN



Thanks aksh1yadav

Thanks Michael_Udhaya

1 Like

Keep it Simple …

inputString = “29/HCGS/416813/001/PN”
outPutString = "S “+inputString.Substring(0,14)+” "+inputString.Substring(15,6)

Hi @Manuvidesh

Also here i would like to share some thoughts of String manipulation.

cheers :smiley:

Happy learning :smiley:


This is great … I have been in the process of compiling a similar list.