展开全部
publicstaticstringMidStrEx(stringsourse,stringstartstr,stringendstr)
{
stringresult=string.Empty;
intstartindex,endindex;
try
{
startindex=sourse.IndexOf(startstr);
if(startindex==-1)
returnresult;
stringtmpstr=sourse.Substring(startindex+startstr.Length);
endindex=tmpstr.IndexOf(endstr);
if(endindex==-1)
returnresult;
result=tmpstr.Remove(endindex);
}
catch(Exceptionex)
{
Log.WriteLog("MidStrExErr:"+ex.Message);
}
returnresult;
}
扩展资料
c#截取两特定字符之间的字符串62616964757a686964616fe4b893e5b19e31333431373932
///
///截取中间字符
///
///全字符串
///开始字符串
///结束字符串
///
publicstaticstringSubstring(stringtext,stringstart,stringend)
{
//intIndexofA=text.IndexOf(start);
//intIndexofB=text.IndexOf(end);
//stringNameText=text.Substring(IndexofA+start.Length,IndexofB-IndexofA+2-end.Length);
Regexrg=newRegex("(?<=("+start+"))[.\\s\\S]*?(?=("+end+"))",RegexOptions.Multiline|RegexOptions.Singleline);
stringNameText=rg.Match(text).Value;
returnNameText;
}