@@ -163,7 +163,7 @@ public static string Substring(this string source, string startString, params st
163163 startIndex = source . IndexOf ( startString , StringComparison . OrdinalIgnoreCase ) ;
164164 if ( startIndex < 0 )
165165 {
166- throw new InvalidOperationException ( string . Format ( "在源字符串中无法找到“{0}”的子串位置" , startString ) ) ;
166+ return string . Empty ;
167167 }
168168 startIndex = startIndex + startString . Length ;
169169 }
@@ -185,7 +185,7 @@ public static string Substring(this string source, string startString, params st
185185 }
186186 if ( endIndex < 0 || endIndex < startIndex )
187187 {
188- throw new InvalidOperationException ( string . Format ( "在源字符串中无法找到“{0}”的子串位置" , endStrings . ExpandAndToString ( ) ) ) ;
188+ return string . Empty ;
189189 }
190190
191191 int length = endIndex - startIndex ;
@@ -210,7 +210,7 @@ public static string SubstringRegex(this string source, string startString, stri
210210 return string . Empty ;
211211 }
212212 string inner = containsEmpty ? "\\ s\\ S" : "\\ S" ;
213- string result = source . Match ( string . Format ( "(?<={0 })([{1 }]+?)(?={2 })" , startString , inner , endString ) ) ;
213+ string result = source . Match ( $ "(?<={ startString } )([{ inner } ]+?)(?={ endString } )") ;
214214 return result . IsMissing ( ) ? null : result ;
215215 }
216216
@@ -293,15 +293,15 @@ public static bool IsIdentityCardId(this string value)
293293 return false ;
294294 }
295295 array = regex . Split ( value ) ;
296- return DateTime . TryParse ( string . Format ( "{0}-{1}-{2}" , " 19" + array [ 2 ] , array [ 3 ] , array [ 4 ] ) , out time ) ;
296+ return DateTime . TryParse ( $ " { " 19" + array [ 2 ] } - { array [ 3 ] } - { array [ 4 ] } " , out time ) ;
297297 }
298298 regex = new Regex ( @"^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9Xx])$" ) ;
299299 if ( ! regex . Match ( value ) . Success )
300300 {
301301 return false ;
302302 }
303303 array = regex . Split ( value ) ;
304- if ( ! DateTime . TryParse ( string . Format ( "{0}-{1}-{2}" , array [ 2 ] , array [ 3 ] , array [ 4 ] ) , out time ) )
304+ if ( ! DateTime . TryParse ( $ " { array [ 2 ] } - { array [ 3 ] } - { array [ 4 ] } " , out time ) )
305305 {
306306 return false ;
307307 }
@@ -817,7 +817,7 @@ public static byte[] ToHexBytes(this string hexString)
817817 public static string ToUnicodeString ( this string source )
818818 {
819819 Regex regex = new Regex ( @"[^\u0000-\u00ff]" ) ;
820- return regex . Replace ( source , m => string . Format ( @"\u{0:x4}" , ( short ) m . Value [ 0 ] ) ) ;
820+ return regex . Replace ( source , m => $ @ "\u{ ( short ) m . Value [ 0 ] : x4 } " ) ;
821821 }
822822
823823 /// <summary>
0 commit comments