RETURN FIRST WORD / TOKEN / STRING

  • Thread starter Thread starter wildman
  • Start date Start date
W

wildman

What's the easiest way to return the first word from a string in
vb.net?

thanks for any help or information.
 
Assuming that you assume words are separated by spaces:

Dim i As String = "Line 0|Line 1|Line 2|Line 3"
Dim a() As String
Dim j As Integer
a = i.Split("|")
For j = 0 To a.GetUpperBound(0)
MsgBox(a(j))
Next


in this example we are using pipes.... should work the same by changing the
i.Split(" ") line

If you are expecting a really long string with 100's of words, i would
recommend looking for the first 'space' within the sentance and then using
the SUBSTRING command to get the first word.
 
Back
Top