/// <summary> /// 截取中间字符 /// </summary> /// <param name="text">全字符串</param> /// <param name="start">开始字符串 </param> /// <param name="end">结束字符串 </param> /// <returns></returns> public static string Substring(string text,string start,string end) { Regex regex = new Regex("(?<=(" + start + "))[.\s\S]*?(?=(" + end + "))", RegexOptions.Multiline | RegexOptions.Singleline); return regex.Match(text).Value; }
/// <summary> /// 包含多个,截取中间字符,返回数组 /// </summary> /// <param name="text">全字符串</param> /// <param name="start">开始字符串 </param> /// <param name="end">结束字符串 </param> /// <returns></returns> public string[] GetAllMatchedItems(string text, string start, string end) { Regex reg = new Regex("(?<=(" + start + "))[.\s\S]*?(?=(" + end + "))", RegexOptions.Multiline | RegexOptions.Singleline); int count = reg.Matches(text).Count; string[] Items = new string[count]; for (int i = 0; i < count; i++) { Items[i] = reg.Matches(text)[i].Value; } return Items; }
/// <summary>
/// 获取双引号间的字符串
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
internal string GetBetweenDoubleQuoteString(string str) {
Regex regex = new Regex(""[^"]*"");
return regex.Match(str).Value.Replace(""", "");
}