在正则表达式中使用var

时间:2017-01-07 17:36:18

标签: regex

我想在文件中搜索特定(变量)字。

private int read_inv(string file, string part) // part = SCRAP
{
    string text = File.ReadAllText(invFolder + file + ".inv");


    string find = @"(?i)\bSCRAP\b"; // this return 3 like it should be
    string find = @"(?i)\b"+part+"\b"; // this return 0

    Regex r = new Regex(find);
    MatchCollection matches = r.Matches(text);
    int iCount = matches.Count;

    return matches.Count;
} 

0 个答案:

没有答案