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”)
Thanks
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.
TanQ,
Michael Udhaya
1 Like
Michael_Udhaya:
29/HCGS/416813/001/PN
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
Regards…!!
Aksh
4 Likes
jOeyO
(Joe)
August 6, 2019, 11:13pm
6
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.
Hi,
if you are a beginner in the world of automation and would like to know how you can manipulate text based on the solutions available in the VB.NET code and using REGEX (regular expressions) then you are in the right place.
In the topic below, you will learn how to easily extract data from any part of the search text using various methods.
The topic includes solution examples with descriptions and graphics to better understand the topic for functions such as:
Split
Substring
Left
Right
R…
cheers
Happy learning
2 Likes
jOeyO
(Joe)
August 7, 2019, 10:59am
8
This is great … I have been in the process of compiling a similar list.
2 Likes