[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

Format string using regular expressions

Alexander Vasilevsky

8/3/2008 2:55:00 PM

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... - Audio tools for C# and VB.Net developers


1 Answer

Pavel Minaev

8/4/2008 6:32:00 AM

0

On Aug 3, 6:54 pm, "Alexander Vasilevsky" <m...@alvas.net> wrote:
> 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));