2

这是我作为一天任务列表输入的用户输入示例

Meeting with developer 60min
Schedule a GoTo Meeting to discuss weekly sprint 45min
15min to code integration.

我们如何提取单词 60min、45min 和 15min 用于我的计算。

4

3 回答 3

5
Regex.Match("Meeting with developer 60min", @"(\d+min)").Groups[1].ToString();
于 2013-06-05T07:07:57.350 回答
4
var output = input.Split(' ', '\n', '\r').Where(i => i.Contains("min"));

编辑处理换行符

于 2013-06-05T07:14:00.863 回答
0

试试看

    string s = "Meeting with developer 60min "+
          "Schedule a GoTo Meeting to discuss weekly sprint 45min "+
          "15min to code integration.";
        foreach (Match match in Regex.Matches(s, @"(?<!\w)60\w+"))
        {
            Console.WriteLine(match.Value);
        }

        foreach (Match match in Regex.Matches(s, @"(?<!\w)15\w+"))
        {
            Console.WriteLine(match.Value);
        }

        foreach (Match match in Regex.Matches(s, @"(?<!\w)45\w+"))
        {
            Console.WriteLine(match.Value);
        }

或简而言之

var output = s.Split(' ').Where(i => i.Contains("min") || i.StartsWith("60") ||    i.StartsWith("15") || i.StartsWith("45"));
            foreach (var o in output)
            {
                Console.WriteLine(o);
            }
于 2013-06-05T07:24:03.433 回答