Function to standardize a telephone number.

public class Form1
{

 private void Form1_Load(object sender, System.EventArgs e)
 {
  string RawPhoneNumber = "(800) 555-1212";
  string StandardizedPhoneNumber = StandardizePhoneNumber(RawPhoneNumber);
  Interaction.MsgBox("Phone number: " + RawPhoneNumber + ControlChars.CrLf + "Standardized: " + StandardizedPhoneNumber);
 }

 public string StandardizePhoneNumber(string PhoneNumber)
 {
  if (PhoneNumber // ERROR: Unknown binary operator Like
 == true) {
   PhoneNumber = System.Text.RegularExpressions.Regex.Replace(PhoneNumber, "\\D", "");
   if (PhoneNumber.StartsWith("1") == false) {
    PhoneNumber = "1" + PhoneNumber;
   }
   if (PhoneNumber // ERROR: Unknown binary operator Like
) {
    ulong PhoneNumberValue = Conversion.Val(Strings.Left(PhoneNumber, 11));
    PhoneNumber = PhoneNumberValue.ToString("0-000-000-0000");
   }
  }
  return PhoneNumber;
 }
 public Form1()
 {
  Load += Form1_Load;
 }

}

No comments:

Post a Comment