DetailPage-MSS-KB

Microsoft small business knowledge base

Article ID: 266289 - Last Review: July 15, 2004 - Revision: 1.3

This article was previously published under Q266289

SUMMARY

This article illustrates how to use the Split function to separate a delimited string into a string array. Although the Microsoft Visual Basic product documentation describes how to use the Split function, the product documentation does not contain an example that uses the Split function.

MORE INFORMATION

The Split Function (http://msdn.microsoft.com/en-us/library/6x627e5f(VS.71).aspx) returns a one-dimensional array, which contains a specified number of substrings. You can use this function to put a string separated by a character delimiters into a string array to get the value of each substring.

Use the following steps to create the sample project:
  1. Create a new Standard EXE project. Form1 is created by default.
  2. Add a CommandButton to Form1.
  3. Add the following code to the code window of Form1:
    Option Explicit
    
    Private Sub Command1_Click()
       Dim strTest As String
       Dim strArray() As String
       Dim intCount As Integer
       
       strTest = "Fred & Wilma & Barney & Betty"
       strArray = Split(strTest, "&")
       
       For intCount = LBound(strArray) To UBound(strArray)
          Debug.Print Trim(strArray(intCount))
       Next
    End Sub
    					
  4. From the View menu, click Immediate Window.
  5. On the Run menu, click Start or press the F5 key to start the program.
  6. Click the Command1 command button.RESULTS: Each name in the strTest variable appears on an individual line.

APPLIES TO
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
Keywords: 
kbhowto kbstring KB266289
Share
Additional support options
Ask The Microsoft Small Business Support Community
Contact Microsoft Small Business Support
Find Microsoft Small Business Support Certified Partner
Find a Microsoft Store For In-Person Small Business Support