34-Splitting Strings

0
296

This Visual Basic Tutorial is all about Splitting Strings.
Split is a function that separates Strings. It receives a string or character delimiter that parses and separates the string into parts.

 

Example:

  1. Dim textLine As String
  2. Dim textArray() As String
  3. 'set a line of text
  4. textLine = "UserName1 Password1 UserName2 Password2"
  5. 'pass it to the array and split it with space
  6. textArray = textLine.Split(" ")
  7.  
  8. 'its segregate the line of text in an array
  9. For i As Integer = 0 To UBound(textArray)
  10.  
  11. MsgBox(textArray(i))
  12.  
  13. Next i

or

  1. Dim textLine As String
  2. Dim textArray() As String
  3. 'set a line of text
  4. textLine = "UserName1, Password1, UserName2, Password2"
  5. 'pass it to the array and split it with comma
  6. textArray = textLine.Split(",")
  7.  
  8. 'its segregate the line of text in an array
  9. For i As Integer = 0 To UBound(textArray)
  10.  
  11. MsgBox(textArray(i))
  12.  
  13. Next i

 

 

Readers might read also:

 

Facebook Comments
(Visited 17 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here