基于对空白奇数分割字符串奇数、字符串、空白

由网友(天性)分享简介:我需要拆分一个字符串,它看起来像这样I need to split a string that looks like this1052 root 0 SW< [hwevent]为以下1052root0SW<[hwevent]当然,我可以只掀起forloop和空格比较字符索引,当发生不是空...

我需要拆分一个字符串,它看起来像这样

I need to split a string that looks like this

1052 root         0 SW<  [hwevent]

为以下

1052
root
0
SW<
[hwevent]

当然,我可以只掀起forloop和空格比较字符索引,当发生不是空白,发生添加到一个新的字符串数组,但我觉得这是一个非常肮脏的方式做到这一点

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?

推荐答案

您可以使用StringSplitOptions.RemoveEmptryEntries

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

相关推荐

最新文章