ppr
(Peter Preuss)
4
e.g. with Regex:

strText
"123456789"
strPattern
"\d{3}"
new Regex(strPattern).Replace(strText,function (m) m.Groups(0).Value & "-").TrimEnd({"-"c})
"123-456-789"
And also:

as another of other options with LINQ along with its typically Overhead at Syntax:

String.Join("",strText.Select(Function (x,i) If((i+1) Mod 3 = 0, x & "-", x)).toArray).TrimEnd("-"c)
"123-456"
1 Like