在线求一方法. 本帖最后由 sky1314 于 2013-01-23 17:21:16 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 int[] rooms = new int[4];List<string> maps = new List<string>(new string[] { "室", "厅", "厨", "卫" });string str = "2室2厅1卫";MatchCollection mc = Regex.Matches(str, "(\\d+)(\\w)");foreach (Match m in mc){ string key = m.Groups[2].Value; int idx = maps.IndexOf(key); if (idx > -1) { rooms[idx] = int.Parse(m.Groups[1].Value); }}for (int i = 0; i < maps.Count; i++){ Console.WriteLine(rooms[i] + maps[i]);}貌似也没偷到什么懒~~~ string str = "2室1厨1卫"; var s = Regex.Matches(str, @"(?is)(?=.*?(?<room>\d+)室)?(?=.*?(?<hall>\d+)厅)?(?=.*?(?<kitchen>\d+)厨)?(?=.*?(?<toilet>\d+)卫)?.+").OfType<Match>().Select(t => new { room = t.Groups["room"].Value, hall = t.Groups["hall"].Value, kitchen = t.Groups["kitchen"].Value, toilet = t.Groups["toilet"].Value }).FirstOrDefault(); string str = "2室2厅1厨1卫"; Match mc = Regex.Match(str, @"((?<room>\d*?)室|(?<hall>\d*?)厅|(?<kitchen>\d*?)厨|(?<toilet>\d*?)卫)*"); var result = new { room = mc.Groups["room"].Value, hall = mc.Groups["hall"].Value, kitchen = mc.Groups["kitchen"].Value, toilet = mc.Groups["toilet"].Value }; /* + result { room = "2", hall = "2", kitchen = "1", toilet = "1" } <Anonymous Type> */ 的重载均与委托 不匹配的问题 还是DataGridView的问题,没办法结贴 可不可以在静态方法中找到调用该方法的对象 那里有net 2003下载 关于C# 里面的window server 服务注册的问题 请高手讲解在DataGrid中,使鼠标到达的行和列显示不同的颜色 关于类的实例化问题……(菜鸟问题50分) 请大家介绍几本C#.NET的入门书籍,给分 数据集中的主键列不区分字符大小写? 显示图片延时问题--有点可怕~ 数据源绑定以及数据库读取保存问题 向大家请教一个 拖动窗口 显示图像 的问题
List<string> maps = new List<string>(new string[] { "室", "厅", "厨", "卫" });
string str = "2室2厅1卫";
MatchCollection mc = Regex.Matches(str, "(\\d+)(\\w)");
foreach (Match m in mc)
{
string key = m.Groups[2].Value;
int idx = maps.IndexOf(key);
if (idx > -1)
{
rooms[idx] = int.Parse(m.Groups[1].Value);
}
}
for (int i = 0; i < maps.Count; i++)
{
Console.WriteLine(rooms[i] + maps[i]);
}
貌似也没偷到什么懒~~~
var s = Regex.Matches(str, @"(?is)(?=.*?(?<room>\d+)室)?(?=.*?(?<hall>\d+)厅)?(?=.*?(?<kitchen>\d+)厨)?(?=.*?(?<toilet>\d+)卫)?.+").OfType<Match>().Select(t => new
{
room = t.Groups["room"].Value,
hall = t.Groups["hall"].Value,
kitchen = t.Groups["kitchen"].Value,
toilet = t.Groups["toilet"].Value
}).FirstOrDefault();
Match mc = Regex.Match(str, @"((?<room>\d*?)室|(?<hall>\d*?)厅|(?<kitchen>\d*?)厨|(?<toilet>\d*?)卫)*");
var result = new {
room = mc.Groups["room"].Value,
hall = mc.Groups["hall"].Value,
kitchen = mc.Groups["kitchen"].Value,
toilet = mc.Groups["toilet"].Value
};
/*
+ result { room = "2", hall = "2", kitchen = "1", toilet = "1" } <Anonymous Type>
*/