Good day,
I would like to know how to add spaces between a string according to its position?
For example, I have a string variable with value “1234567890”. What I want is for the final value to have a format like this: “1234 567 890”. Thank you.
Good day,
I would like to know how to add spaces between a string according to its position?
For example, I have a string variable with value “1234567890”. What I want is for the final value to have a format like this: “1234 567 890”. Thank you.
Assign activity:
String_Variable = “1234567890”
Assign activity:
Variable = System.Text.RegularExpressions.Regex.Replace(String_Variable, “(\d{4})(\d{3})(\d{3})”, “$1 $2 $3”)
hi
StringVar.Substring(0,4) + " “+StringVar.Substring(4,3) +” "+ StringVar.Substring(7)
cheers
Hi @Bruskie143
Try this
Input.Insert(4, " ").Insert(8, " ")
Input.Substring(0, 4) + " " + Input.Substring(4, 3) + " " + Input.Substring(7)
@Moulika_Kaviti hello. May I know what the $1, $2, and $3 means?
Hi @Bruskie143
=> Assign -> StrValue = "1234567890"
=> Assign -> Output = StrValue.Insert(4, " ").Insert(8," ")
Now Output contains the formatted value “1234 567 890”
Check the below image for workflow
Hope it helps!!
$1: Refers to the first four digits of the original string.
(space): Adds a space
$2: next 3 digits
$3: final 3
String.Format("{0} {1} {2}", Input.Substring(0, 4), Input.Substring(4, 3), Input.Substring(7))
I hope it helps!!
Hello
Another option
Assign activity:
String_Variable = “1234567890”
Assign activity:
Variable = System.Text.RegularExpressions.Regex.Replace(String_Variable, “(?<=^\d{4})|(?<=^\d{7})”, “ ”)
Cheers
Steve
Hi,
Try this
inputString = “1234567890”
outputString = inputString.Substring(0, 4) + " " + inputString.Substring(4, 3) + " " + inputString.Substring(7)