把123456789转换为12-345-6789的三种方法
方法一:
string str = 123456789;
str = int.Parse(str).ToString("##-###-####");
方法二:
string str = "123456789";
str = str.Insert(5,"-");
str = str.Insert(2, "-");
方法三:
首先引入命名空间:using System.Text.RegularExpressions
//Regex reg = new Regex(@"^(\d{2})(\d{3})(\d{4})$");
或者
Regex reg = new Regex(@"^(\d{2})(\d{3})(\d{4})$");
str = reg.Replace(str,"$1-$2-$3");