美文网首页
【C#】根据正则表达式获取结果

【C#】根据正则表达式获取结果

作者: KevinTseng | 来源:发表于2018-06-12 21:37 被阅读0次
/// <summary>
/// 根据正则表达式获取结果
/// </summary>
/// <param name="v"></param>
/// <param name="str"></param>
/// <returns></returns>
public static string getRegexResult(string pat, string v, string type)
{
    string str = "";
    Regex r = new Regex(pat, RegexOptions.IgnoreCase);
    Match m = r.Match(v);
    int matchCount = 0;
    if (m.Success)
    {
        ++matchCount;
        Group g = m.Groups[1];
        if (type == "num")
        {
            str = " = " + g.Value;
        }
        else if (type == "string")
        {
            str = " = \"" + g.Value + "\"";
        }
    }
    return str;
}

相关文章

网友评论

      本文标题:【C#】根据正则表达式获取结果

      本文链接:https://www.haomeiwen.com/subject/ynareftx.html