public int index(string content,string str) { return content.IndexOf(str); } public int index(string content, string str, int fromindex) { return content.IndexOf(str, fromindex); } public int strlen(string content,string start, string end) { return index(content, end) - index(content, start); } public int strlen(string content, string start,string end,int fromindex,int fromendindex) { int endindex = index(content, end, fromendindex); int startindex=index(content, start,fromindex); return endindex - startindex; } /// <summary> /// 截取字符串 /// </summary> /// <param name="content">完整的内容</param> /// <param name="start">开始子字符串</param> /// <param name="startoffset">设置开始字符串的偏移量,一般为0即可</param> /// <param name="end">结束子字符串</param> /// <param name="endoffset">结束子字符串的偏移量,一般为0即可</param> /// <param name="fromindex">起始的搜索未知,通常为0即可,若内容中有多个匹配,可设置此参数来达过滤</param> /// <param name="fromendindex">同上</param> /// <returns>返回开始子字符串和结束子字符串中间的内容,包含开始子字符串和结束子字符串</returns> public string cutstr(string content, string start, int startoffset,string end,int endoffset,int fromindex,int fromendindex) { int startindex = index(content, start,fromindex)+startoffset; int len = strlen(content, start, end,fromindex,fromendindex)-startoffset+endoffset; return content.Substring(startindex, len+end.Length); }