diff --git a/Infrastructure/Extensions/StringExtension.cs b/Infrastructure/Extensions/StringExtension.cs index 46c1baa..8df3173 100644 --- a/Infrastructure/Extensions/StringExtension.cs +++ b/Infrastructure/Extensions/StringExtension.cs @@ -106,5 +106,33 @@ namespace Infrastructure.Extensions return string.IsNullOrEmpty(str) ? str : str.Substring(0, 1).ToUpper() + str[1..]; } + /// + /// 截取指定字符串中间内容 + /// + /// + /// + /// + /// + 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; + } } }