String.Format("{0:###-###-####}", customer.ContactHome); //NOT working (9891205789)
String.Format("{0:###-###-####}", Convert.ToInt64(customer.ContactHome)); //Works fine (989-120-5789)
,但我不想投手机不会因某种原因。如何在不投射时格式化电话号码?
String.Format("{0:###-###-####}", customer.ContactHome); //NOT working (9891205789)
String.Format("{0:###-###-####}", Convert.ToInt64(customer.ContactHome)); //Works fine (989-120-5789)
,但我不想投手机不会因某种原因。如何在不投射时格式化电话号码?
如果customer.ContactHome是字符串,你可以这样做:
Regex.Replace(customer.ContactHome, "(\d\d\d)(\d\d\d)(\d\d\d\d)", "$1-$2-$3");
或
customer.ContactHome.Substring(0,3) + "-" +
customer.ContactHome.Substring(3,3) + "-" +
customer.ContactHome.Substring(6,4);
如果customer.ContactHome
是string
,它不会使用数字格式进行格式化,因为它已经是一个字符串和格式字符串需要一个数字。
如果你不想使用正则表达式,也可以使用String这样的方法来获得格式化的字符串值。
whats ContactHome原创类型? – ariel 2011-05-06 07:38:28