Last active
May 29, 2023 08:38
-
-
Save itn3000/0b59f284b38eb9347ed18fe3027ef863 to your computer and use it in GitHub Desktop.
split string test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Text; | |
// space(U+0020),tab(U+0009),fullwidth space(U+3000),linefeed(U+000a) | |
var str = "a b\tc d\n"; | |
foreach(var x in str.Split(' ')) | |
{ | |
Console.WriteLine($"a: '{x}'"); | |
} | |
foreach(var x in str.Split(null)) | |
{ | |
Console.WriteLine($"b: '{x}'"); | |
} | |
foreach(var x in str.Split("")) | |
{ | |
Console.WriteLine($"c: '{x}'"); | |
} | |
foreach(var x in str.Split(new char[0])) | |
{ | |
Console.WriteLine($"d: '{x}'"); | |
} | |
foreach(var x in str.Split(default(string[]), StringSplitOptions.None)) | |
{ | |
Console.WriteLine($"e: '{x}'"); | |
} | |
foreach(var x in str.Split(new string[0], StringSplitOptions.None)) | |
{ | |
Console.WriteLine($"f: '{x}'"); | |
} | |
foreach(var x in str.Split(new string[]{ "" }, StringSplitOptions.None)) | |
{ | |
Console.WriteLine($"g: '{x}'"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a: 'a' | |
a: 'b c d | |
' | |
b: 'a' | |
b: 'b' | |
b: 'c' | |
b: 'd' | |
b: '' | |
c: 'a b c d | |
' | |
d: 'a' | |
d: 'b' | |
d: 'c' | |
d: 'd' | |
d: '' | |
e: 'a' | |
e: 'b' | |
e: 'c' | |
e: 'd' | |
e: '' | |
f: 'a' | |
f: 'b' | |
f: 'c' | |
f: 'd' | |
f: '' | |
g: 'a b c d | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment