Separate string with space after the first two numbers and then after that after each three numbers with spacing?

Have an input which could be 8 digits
12345678
What is the suitable command to use in order to add in a space after the first two numbers and then a space for every three numbers after that then.
Input: 12345678
Output: 12 345 678
Any suggestions would be appreciated please.
Thanks

Hi @ciaramkm,

Please find the solution.

input=“12345678”
output=input.Substring(0,2)+" “+input.Substring(2,3)+” "+input.Substring(4,4).Remove(0,1)

Regards,
Omkar P

1 Like

@ciaramkm

the simplest way could be

String.Format("{0:00 000 000}", 12345678)

image

Thanks
Arif Elahi

2 Likes

Thanks for your help :slight_smile:

1 Like

SeparateString.xaml (7.5 KB)

Try this.

@ciaramkm

Please avoid pure string manipulations for this. You can broaden this to humanization and rely on integrated tools designed for this purpose. Here, I use french output (that fit your expected output) but you can set your target culture.

CInt(Input).ToString("#,##0", New System.Globalization.CultureInfo("fr-FR"))

1 Like

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