From 4cb7296767bc42d5e3efba7075f55c72fb62c9b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Sat, 8 Jan 2022 21:46:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=88=AA=E5=8F=96=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E5=86=85=E5=AE=B9=E7=9B=B4=E6=8E=A5=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Infrastructure/Extensions/StringExtension.cs | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) 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; + } } }