增加截取指定内容直接方法
This commit is contained in:
parent
175475af62
commit
4cb7296767
@ -106,5 +106,33 @@ namespace Infrastructure.Extensions
|
||||
return string.IsNullOrEmpty(str) ? str : str.Substring(0, 1).ToUpper() + str[1..];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 截取指定字符串中间内容
|
||||
/// </summary>
|
||||
/// <param name="sourse"></param>
|
||||
/// <param name="startstr"></param>
|
||||
/// <param name="endstr"></param>
|
||||
/// <returns></returns>
|
||||
public static string SubstringBetween(this 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)
|
||||
{
|
||||
Console.WriteLine("MidStrEx Err:" + ex.Message);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user