【C#】字符串提取(获取两个字符串中间的字符串)
【C#】字符串提取(获取两个字符串中间的字符串)
https://blog.csdn.net/weixin_43553508/article/details/102673668
C#三行代码实现提取两个字符之间的字符串
https://blog.csdn.net/qq_25760257/article/details/127147703?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-1-127147703-blog-102673668.pc_relevant_landingrelevant&spm=1001.2101.3001.4242.2&utm_relevant_index=4
/// <summary>
/// 通过 IndexOf 截取中间字符串
/// </summary>
/// <param name="source"></param>
/// <param name="startStr"></param>
/// <param name="endStr"></param>
/// <returns></returns>
public static string MiddleSearchStr(this string source, string startStr, string endStr)
{
string resStr=string.Empty;
try
{
int spildStrIndex = source.IndexOf(startStr, 0);
if (spildStrIndex < 0)
{
return resStr;
}
var strartIndex = spildStrIndex + startStr.Length;
var endIndex = source.IndexOf(endStr, strartIndex);
resStr = source.Substring(strartIndex, endIndex - strartIndex);
}
catch (Exception)
{
}
return resStr;
} string ExtractStr(string source, string startStr, string endStr) { string[] strartStrArray = source.Split(startStr, StringSplitOptions.None); string[] endStrArray = strartStrArray[1].Split(endStr, StringSplitOptions.None); var sss2 = endStrArray[0]; return ""; }