草庐IT

731478718861993983

全部标签

c# - 在 MVC/C# 中格式化字符串

我有一个字符串731478718861993983,我想使用C#获取这个73-1478-7188-6199-3983。我怎样才能像这样格式化它?谢谢。 最佳答案 通过使用正则表达式:publicstaticstringFormatTest1(stringnum){stringformatPattern=@"(\d{2})(\d{4})(\d{4})(\d{4})(\d{4})";returnRegex.Replace(num,formatPattern,"$1-$2-$3-$4-$5");}//teststringtest=Form