Alex Rivera | Logout

Splitting a string at all whitespace

Asked 2009-10-13T21:23:10.923
19

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!

This has been bugging me for quite a while now, as my syntax highlighter I made completely ignores the first word in each line except for the very first line.

Edit
Report

2 Answers

32

String.Split() (no parameters) does split on all whitespace (including LF/CR)

answered 2009-10-13T21:27:31.600
-1
Dim words As String = "This is a list of words, with: a bit of punctuation" + _
                          vbTab + "and a tab character." + vbNewLine
Dim split As String() = words.Split(New [Char]() {" "c, CChar(vbTab), CChar(vbNewLine) })
answered 2009-10-13T21:26:41.643

Your Answer