Formats a number (series of single numbers) to a phone number format xxx-xxx-xx-xx - CSharp System

CSharp examples for System:Math Number

Description

Formats a number (series of single numbers) to a phone number format xxx-xxx-xx-xx

Demo Code

/* *******************************************************************************
 * Copyright (c) 2005-2012 Zibler S de RL MI.
 * // ww w . ja  va  2 s  .c  o  m
 * This file is part of Zibler.
 * 
 * Zibler is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Zibler is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Zibler.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * *******************************************************************************/
using System.Threading;
using System.Text;
using System.Security.Cryptography;
using System;

public class Main{
        /// <summary>
        /// Formats a number (series of single numbers) to a phone number format
        /// xxx-xxx-xx-xx
        /// </summary>
        /// <param name="number">number</param>
        /// <returns>Formatted nmber</returns>
        public static string FormatNumberToPhoneNumber (string number)
        {
            if (number.Length == 10)
            {
                double y = Double.Parse (number);
                string returnString = String.Format ("{0:(###) ###-##-##}", y);
                return returnString;
            }
            else
                return number;
        }
}

Related Tutorials