/// <summary> /// 文本取左边 /// </summary> /// <param name="str"></param> /// <param name="Left"></param> /// <param name="pos"></param> /// <returns></returns> ) { ) { pos = ; } int index = str.IndexOf(Left, pos, StringComparison.Ordinal); ) { return ""; } , index); } /// <summary> /// 取文本右边 /// </summary> /// <param name="str"></param> /// <param name="right"></param> /// <param name="pos">起始寻找位置</param> /// <returns></returns> ) { pos = pos == ? right.Length : pos; int index = str.IndexOf(right, pos, StringComparison.Ordinal); ) { return ""; } return str.Substring(index + right.Length); } /// <summary> /// 取文本中间 /// </summary> /// <param name="allStr">原字符</param> /// <param name="firstStr">前面的文本</param> /// <param name="lastStr">后面的文本</param> /// <returns></returns> public static string GetMid(string allStr, string firstStr, string lastStr) { //取出前面的位置 int index1 = allStr.IndexOf(firstStr); ) { index1 = index1 + firstStr.Length; } //取出后面的位置 int index2 = allStr.IndexOf(lastStr, index1); || index2 == -) { return ""; } //取出文本 return allStr.Substring(index1, index2 - index1); }