截取中间部分字符串
作者:互联网
截取任意字符中间的字符串,就得用到正则了,否则不好截取
/// <summary> /// 获得字符串中开始和结束字符串中间得值 /// </summary> /// <param name="str">字符串</param> /// <param name="s">开始</param> /// <param name="e">结束</param> /// <returns></returns> public static string GetValue(string str, string s, string e) { Regex rg = new Regex("(?<=(" + s + "))[.\\s\\S]*?(?=(" + e + "))", RegexOptions.Multiline | RegexOptions.Singleline); return rg.Match(str).Value; }
标签:Regex,string,截取,GetValue,中间,字符串 来源: https://www.cnblogs.com/messi-10/p/16350716.html