Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I need to split a string that looks like this

1052 root         0 SW<  [hwevent]

into the following

1052
root
0
SW<
[hwevent]

sure, I could just whip up a forloop and compare character indices with white spaces and when the occurrence is not a white space, add the occurrence to a new string array but I feel like this is a really dirty way to do this.

What is a good way to split this string? Regex perhaps?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
310 views
Welcome To Ask or Share your Answers For Others

1 Answer

You may use StringSplitOptions.RemoveEmptryEntries

string strtemp = "1052 root         0 SW<  [hwevent]";
string[] array = strtemp.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...