[C#] 纯文本查看 复制代码 /// 获得字符串中开始和结束字符串中间得值
/// </summary>
/// <param name="html">Html字符串</param>
/// <param name="s">开始</param>
/// <param name="e">结束</param>
/// <returns></returns>
private string GetValue(string html, string start, string end)
{
Regex rg = new Regex("(?<=(" + start + "))[.\\s\\S]*?(?=(" + end + "))", RegexOptions.Multiline | RegexOptions.Singleline);
return rg.Match(html).Value;
}
#region 获得字符串中开始和结束字符串中间得值
/// <summary>
/// 获得字符串中开始和结束字符串中间得值
/// </summary>
/// <param name="begin">开始匹配标记</param>
/// <param name="end">结束匹配标记</param>
/// <param name="html">Html字符串</param>
/// <returns>返回中间字符串</returns>
public static List<string> GetMidValues(string begin, string end, string html)
{
List<string> strList = new List<string>();
Regex reg = new Regex("(?<=(" + begin + "))[.\\s\\S]*?(?=(" + end + "))", RegexOptions.Multiline | RegexOptions.Singleline);
MatchCollection m = reg.Matches(html);
foreach (Match item in m)
{
strList.Add(item.Value);
}
return strList;
}
#endregion
例如以上两个方法,我暂时是用这两个,希望飞哥能有更好的写法和效率
|