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