C# 获取两个字符串之间是字符方法(备用)

public static string MidStrEx(string sourse, string startstr, string endstr)
{
string result = string.Empty;
int startindex, endindex;
try
{
startindex = sourse.IndexOf(startstr);
if (startindex == -1)
return result;
string tmpstr = sourse.Substring(startindex + startstr.Length);
endindex = tmpstr.IndexOf(endstr);
if (endindex == -1)
return result;
result = tmpstr.Remove(endindex);
}
catch (Exception ex)
{
Log.WriteLog("MidStrEx Err:" + ex.Message);
}
return result;
}

  

posted @ 2023-06-07 15:33  liaoyi  阅读(64)  评论(0编辑  收藏  举报