//834858dsdf-12-34513-99
string s1 = "";
string msg = "834858dsdf-12-34513-99";
Regex regex = new Regex(@"\d+", RegexOptions.ECMAScript);
Match match = regex.Match(msg);
while (match.Value.Length != 0)
{
s1 = Join(match.Value, -);
match = regex.Match(msg, match.Index + match.Value.Length);
}
Console.WriteLine(s1);
Console.ReadKey();
static string Join(string[] strs, string seperater)//加上分隔符“-”
{
string result = "";
for (int i = 0; i < strs.Length - 1; i++)
{
result = result + strs[i] + seperater;
}
if (strs.Length > 0)
{
result = result + strs[strs.Length - 1];
}
return result;
}
运行结果:834858-12-34513-99