Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > taking apart a string and putting into array


Reply
 
Thread Tools Display Modes
  #1  
Old 05-24-2004, 05:45 AM
Protoculture Protoculture is offline
Freshman
 
Join Date: May 2004
Posts: 43
Default taking apart a string and putting into array


I have the following string stored in a variable called ToPrint

"print1.pdf, print2.pdf, print3.pdf"

I need to grab each item and store it into an array so I have the following array...

MyArray[1] = print1.pdf
MyArray[2] = print2.pdf
MyArray[3] = print3.pdf

How can this be done?
Reply With Quote
  #2  
Old 05-24-2004, 05:50 AM
waits77 waits77 is offline
Senior Contributor
 
Join Date: May 2003
Posts: 805
Default

Use Split() with "," as the delimiter
Reply With Quote
  #3  
Old 05-24-2004, 06:00 AM
doofusboy doofusboy is offline
Centurion
 
Join Date: Sep 2003
Posts: 183
Default

Code:
Dim ToPrint As String
Dim MyArray(2) As String
ToPrint = "print1.pdf, print2.pdf, print3.pdf"
For i = 0 To UBound(Split(ToPrint, ","))
    MyArray(i) = Split(ToPrint, ",")(i)
    MsgBox MyArray(i)
Next i
Reply With Quote
  #4  
Old 05-24-2004, 07:38 AM
Diurnal Diurnal is offline
Enthusiast

Retired Leader
* Expert *
 
Join Date: Apr 2002
Location: Bellevue, WA.
Posts: 3,233
Default

Quote:
Originally Posted by doofusboy
Code:
Dim ToPrint As String
Dim MyArray(2) As String
ToPrint = "print1.pdf, print2.pdf, print3.pdf"
For i = 0 To UBound(Split(ToPrint, ","))
    MyArray(i) = Split(ToPrint, ",")(i)
    MsgBox MyArray(i)
Next i
The split function uses a dynamic array to operate.
Code:
Dim MyArray() As String MyArray() = Split(ToPrint, ",") For i = 0 to UBound(MyArray) Me.Print MyArray(i) Next i
Reply With Quote
  #5  
Old 05-24-2004, 10:12 AM
doofusboy doofusboy is offline
Centurion
 
Join Date: Sep 2003
Posts: 183
Default

Quote:
Originally Posted by Diurnal
The split function uses a dynamic array to operate.
Code:
Dim MyArray() As String MyArray() = Split(ToPrint, ",") For i = 0 to UBound(MyArray) Me.Print MyArray(i) Next i

Thanks; knew it was SOMETHING like that!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Write 2D array to a file Dolptrmn File I/O and Registry 4 11-08-2003 07:42 PM
Putting string in alphabetical order Marcie General 2 04-13-2003 10:08 PM
Problem with session variables array Netrunner Web Programming 2 04-03-2003 05:32 AM
Short Tutorial: Wide String (unicode) API Calls Riemann API 0 03-24-2003 07:06 PM
File format problem kingesk General 1 09-08-2000 04:52 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->