I need to split a string at all whitespace, it should ONLY contain the words themselves.
How can I do this in vb.net?
Tabs, Newlines, etc. must all be split
If you want to avoid regex, you can do it like this:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit"
.Split()
.Where(x => x != string.Empty)
Visual Basic equivalent:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit" _
.Split() _
.Where(Function(X$) X <> String.Empty)
The Where()
is important since, if your string has multiple white space characters next to each other, it removes the empty strings that will result from the Split()
.
At the time of writing, the currently accepted answer (https://stackoverflow.com/a/1563000/49241) does not take this into account.