SPLITTING STRING WITH DELIMETER

HII,

I have a value 123456789
But I want to convert it like 123-456-789

Can Any one help me how to write this expression?

we can do on string method base (when length is fixed)
grafik

or with the help of regex

thank you.

If in case of variable length, then how can we do this

e.g. with Regex:
grafik


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

And also:
grafik

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

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

Thank you it helped me.

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