Format string using regular expressions

  • Thread starter Alexander Vasilevsky
  • Start date
A

Alexander Vasilevsky

There is a phone number in a string such as "3223223" to format it as a
"322-32-23", using regular expressions. Is it possible?

http://www.alvas.net - Audio tools for C# and VB.Net developers
 
P

Pavel Minaev

There is a phone number in a string such as "3223223" to format it as a
"322-32-23", using regular expressions. Is it possible?

Regular expressions are used to parse strings, not to format them. Can
you clarify why you think you need them here?

In the specific case that you give, what's wrong with this:

var result = string.Format("{0}-{1}-{2}", input.Substring(0, 3),
input.Substring(3, 2), input.Substring(5, 2));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top