C#,解析字符串的问题

Roy12 2012-05-21 09:08:55
问下各位,在C# 中用代码解析以下字符串怎么做最简单:
输入字符串: our address is: 9 (2): 86-91
输出字符串: our address is district 9, no. 2, block 86-91
其中的几个数字是动态的。
...全文
129 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Roy12 2012-05-21
  • 打赏
  • 举报
回复
多谢多谢,马上结贴
dalmeeme 2012-05-21
  • 打赏
  • 举报
回复
		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();

输出:
our address is district 9, no. 2, block 86-91
TM_LiuYan 2012-05-21
  • 打赏
  • 举报
回复
数字用正则?

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧