(转)把123456789转换为12-345-6789的3种方法

方法一:

C# CODE
            string a = "123456789";
            a = int.Parse(a).ToString("##-###-####");
            Console.Write(a);

方法二:

C# CODEstring a = "123456789";
            a = a.Insert(5, "-").Insert(2, "-");
            Console.Write(a);

方法三:

C# CODEusing System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            string a = "123456789";

            Regex reg = new Regex(@"^(d{2})(d{3})(d{4})$");
            a = reg.Replace(a, "$1-$2-$3");
            Console.Write(a);
        }
       
    }
}

posted @ 2010-03-23 09:52  PROS  阅读(408)  评论(0)    收藏  举报