【发布时间】:2015-02-18 07:22:28
【问题描述】:
protected void Page_Load(object sender, EventArgs e)
{
lab.Text = FormatTelephoneNumber("0034523");
}
public static string FormatTelephoneNumber(string value)
{
value = new System.Text.RegularExpressions.Regex(@"\D").Replace(value, string.Empty);
return Convert.ToInt64(value).ToString(" #- ###-###");
}
给出输出:
34-523
但我需要输出:
0-034-523
0034523 将变为 0-034-523 和 00345 将变为 0-034-5(无额外值或 0- 000-345)
【问题讨论】:
-
在格式化之前使用PadLeft(7, '0') 将
0字符添加到您的字符串中 -
您希望输入“034523”、“34523”、“0034523”给出不同的结果吗?如果是这样,您绝对应该不将它们转换为整数。
-
return Convert.ToInt64(value).ToString("#- ###-###");此行使用未转换的 0 值。那么如何评价回报。请举个例子。
标签: c#