Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Reformatting a string
Message
De
11/12/2007 17:32:09
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 8.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01274953
Message ID:
01274966
Vues:
9
I just went through this exact same exercise using regular expressions. My code is C#, but VB would be similar.
using System.Text.RegularExpressions;

private string ReformatPhone(string phone)
        {
            Match m = Regex.Match(phone, @"^\(?(\d{3})\)?[\s\-]?(\d{3})\-?(\d{4})$");
            return String.Format("{0}-{1}-{2}", m.Groups[1], m.Groups[2], m.Groups[3]);
        }
>I'm writing a system that receives data from another system using c#. I'm wondering if there is a easy way to parse or transform a string.
>
>example:
>data comes as: (555)555-1234
>Need to convert to: 555-555-1234
>
>I'm planning on just looping through the length of the string and looking for the ( ), but I thought C# might have a wonder tool I could use.
>
>Thanks
>
>Kirk
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform