Spacing '-' every after 2 characters

Hi Team,

Can someone help me to space “-” after every 2 charachters.

Example - str = “123456”
expected output - “12-34-56”

You can use regular expressions like below to add ‘-’ after every 2 characters, remove the last ‘-’ if present.

Regex.Replace(str , “.{2}”, “$0-”).TrimEnd(CChar("-"))

3 Likes

For me Regex not working, can you please help me in this.

IF Currency variable has initial value of “123456”, then do:
image

2 Likes

@Hitesh1 - pls try

System.Text.RegularExpressions.Regex.Replace(myString, ".{2}", "$0-");

input : 123456
output : 12-34-56

1 Like

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