October 21, 2018
Hot Topics:

Discovering Arrays

  • November 20, 2002
  • By Karl Moore
  • Send Email »
  • More Articles »

There are two extra Visual Basic functions you might find amazingly useful; Split and Join.

  • Split Takes a string, such as 'This is my sentence' and splits it up into individual array elements, depending on a 'delimiter'. In this case, the delimiter could be a space (" "), meaning we get an array of four elements containing This, Is, My, Sentence.
  • Join This does the opposite of Split. It takes data from an array and shoves it all together into one long string, with an optional delimiter (which separates the bits of information from each other). So, if we used this on the array created above with a space delimiter (" "), it would take This, Is, My, Sentence and throw them all together, adding spaces in between. In other words, we get back our original sentence 'This is my sentence'.

These concepts always seem exceptionally weird when explained like this - so let's conclude this section with a geek peek at some sample code:

Private Sub Command1_Click()Dim strFirstText As StringDim strSecondText As StringDim StringArray() As StringstrFirstText = "This is my sentence"' First, the splitStringArray = Split(strFirstText, " ")For i = LBound(StringArray) To UBound(StringArray)MsgBox StringArray(i)Next i' And now the joinstrSecondText = Join(StringArray, " ")MsgBox strSecondText    End Sub

Page 9 of 11

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.


Thanks for your registration, follow us on our social networks to keep up-to-date