How do I split text that has no spaces or any characters

Hi, how do I split text that has no spaces or any characters?
E.g. 123456789
I would like to split into: 12 34 56 - I need the first 6 characters separated by spaces.

Hi @sullivanne

Use this

inputString="123456789"
Output=inputString.Substring(0, 2) & " " & inputString.Substring(2, 2) & " " & inputString.Substring(4, 2)

Regards,

Hi,

How about the following expression?

System.Text.RegularExpressions.Regex.Replace(yourString,"^(..)(..)(..).*$","$1 $2 $3")

Regards,

@sullivanne

Another approach

inputString="123456789"
Output=String.Join(" ", Enumerable.Range(0, 3).Select(Function(i) inputString.Substring(i * 2, 2)))

Regards,

1 Like

grafik

with the option that we also can find a more compact version

1 Like

grafik

1 Like
String.Join("", str_input.Take(6).Select(Function(c, i) If(i Mod 2 = 1, c.ToString() & " ", c.ToString())).ToArray()).Trim()

1 Like

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