This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed
tests/ServiceStack.Text.Tests Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -335,6 +335,42 @@ private static byte[] FastToUtf8Bytes(string strVal)
335
335
return bytes ;
336
336
}
337
337
338
+ public static string GetLeftPart ( this string strVal , char needle )
339
+ {
340
+ if ( strVal == null ) return null ;
341
+ var pos = strVal . IndexOf ( needle ) ;
342
+ return pos == - 1
343
+ ? strVal
344
+ : strVal . Substring ( 0 , pos ) ;
345
+ }
346
+
347
+ public static string GetLeftPart ( this string strVal , string needle )
348
+ {
349
+ if ( strVal == null ) return null ;
350
+ var pos = strVal . IndexOf ( needle , StringComparison . OrdinalIgnoreCase ) ;
351
+ return pos == - 1
352
+ ? strVal
353
+ : strVal . Substring ( 0 , pos ) ;
354
+ }
355
+
356
+ public static string GetRightPart ( this string strVal , char needle )
357
+ {
358
+ if ( strVal == null ) return null ;
359
+ var pos = strVal . IndexOf ( needle ) ;
360
+ return pos == - 1
361
+ ? strVal
362
+ : strVal . Substring ( pos + 1 ) ;
363
+ }
364
+
365
+ public static string GetRightPart ( this string strVal , string needle )
366
+ {
367
+ if ( strVal == null ) return null ;
368
+ var pos = strVal . IndexOf ( needle , StringComparison . OrdinalIgnoreCase ) ;
369
+ return pos == - 1
370
+ ? strVal
371
+ : strVal . Substring ( pos + needle . Length ) ;
372
+ }
373
+
338
374
public static string [ ] SplitOnFirst ( this string strVal , char needle )
339
375
{
340
376
if ( strVal == null ) return TypeConstants . EmptyStringArray ;
Original file line number Diff line number Diff line change @@ -16,6 +16,14 @@ public void Can_SplitOnFirst_char_needle()
16
16
Assert . That ( parts [ 1 ] , Is . EqualTo ( "pass@w:rd" ) ) ;
17
17
}
18
18
19
+ [ Test ]
20
+ public void Can_GetLeftPart_and_GetLeftPart_char_needle ( )
21
+ {
22
+ var str = "user:pass@w:rd" ;
23
+ Assert . That ( str . GetLeftPart ( ':' ) , Is . EqualTo ( "user" ) ) ;
24
+ Assert . That ( str . GetRightPart ( ':' ) , Is . EqualTo ( "pass@w:rd" ) ) ;
25
+ }
26
+
19
27
[ Test ]
20
28
public void Can_SplitOnFirst_string_needle ( )
21
29
{
@@ -24,6 +32,14 @@ public void Can_SplitOnFirst_string_needle()
24
32
Assert . That ( parts [ 1 ] , Is . EqualTo ( "pass@w:rd" ) ) ;
25
33
}
26
34
35
+ [ Test ]
36
+ public void Can_GetLeftPart_and_GetLeftPart_string_needle ( )
37
+ {
38
+ var str = "user::pass@w:rd" ;
39
+ Assert . That ( str . GetLeftPart ( "::" ) , Is . EqualTo ( "user" ) ) ;
40
+ Assert . That ( str . GetRightPart ( "::" ) , Is . EqualTo ( "pass@w:rd" ) ) ;
41
+ }
42
+
27
43
[ Test ]
28
44
public void Can_SplitOnLast_char_needle ( )
29
45
{
You can’t perform that action at this time.
0 commit comments