【C#】根据正则表达式获取结果
/// <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
网友评论