问下各位,在C# 中用代码解析以下字符串怎么做最简单:
输入字符串: our address is: 9 (2): 86-91
输出字符串: our address is district 9, no. 2, block 86-91
其中的几个数字是动态的。
输入字符串: our address is: 9 (2): 86-91
输出字符串: our address is district 9, no. 2, block 86-91
其中的几个数字是动态的。
Match match = Regex.Match(s, @"our address is:\s*(\d+)\s*\((\d+)\):\s*([0-9\-]+)");
string r = string.Format(@"our address is district {0}, no. {1}, block {2}", match.Groups[1].Value, match.Groups[2].Value, match.Groups[3].Value);
Console.Write(r);
Console.ReadKey();
输出:
our address is district 9, no. 2, block 86-91