把123456789转换为12-345-6789的3种方法
2012-01-17 11:33
253 查看
方法一:
string a = "123456789";
a = int.Parse(a).ToString("##-###-####");
Console.Write(a);
方法二:
string a = "123456789";
a = a.Insert(5, "-").Insert(2, "-");
Console.Write(a);
方法三:
using 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);
}
}
}
相关文章推荐
- C#优化字符串操作(6)--把123456789转换为12-345-6789的3种方法
- 把123456789转换为12-345-6789的3种方法
- 把123456789转换为12-345-6789的三种方法
- DataTable 转换成 Json的3种方法
- js 字符串转换成数字的3种方法
- int 与 byte[] 的相互转换 关于 int 与 byte[] 的相互转换,Mattias Sjogren 介绍了3种方法
- JS中将一个值转换为字符串的3种方法
- DataTable 转换成 Json的3种方法
- JAVA中3种将byte转换为String的方法
- SpringMVC日期格式类型转换问题--3种处理方法
- DataTable 转换成 Json的3种方法
- JAVA中3种将byte转换为String的方法
- JAVA中3种将byte转换为String的方法
- 用jquery解析JSON数据的方法以及字符串转换成json的3种方法
- DataTable 转换成 Json的3种方法
- map转换成JSON的3种方法
- php类型转换的3种方法
- JAVA中3种将byte转换为String的方法
- DataTable 转换成 Json的3种方法
- JAVA中3种将byte转换为String的方法