首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#解析字符串的有关问题

2012-05-22 
C#,解析字符串的问题问下各位,在C# 中用代码解析以下字符串怎么做最简单:输入字符串: our address is: 9 (

C#,解析字符串的问题
问下各位,在C# 中用代码解析以下字符串怎么做最简单:
输入字符串: our address is: 9 (2): 86-91
输出字符串: our address is district 9, no. 2, block 86-91
其中的几个数字是动态的。

[解决办法]
数字用正则?
[解决办法]

C# code
        string s = "our address is: 9 (2): 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(); 

热点排行