Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

putting space delimited text into an array 1

Status
Not open for further replies.

MrSparkle

Programmer
May 19, 2001
9
0
0
GB
Is there a way to put text like this: (without the quotes, imagine it as a string)

"talk Person hello there"

into a string (or variant) array, like this:

MyString(0) = "talk"
MyString(1) = "Person"
MyString(2) = "hello"
MyString(3) = "there"

it can be comma delimited if it has to be, like "talk,Person,hello there" but i need to know how to do this!

all replies gratefully accepted. the winning reply gets a free box of Mr Sparkle Cleaning Detergent.
 
ReDim Array(0) As String
Dim Text As String
Dim StartPos As Integer, Length As Integer
Dim WordCount As Integer
WordCount = 0
Text = "talk Person hello there"
StartPos = 1
Length = InStr(1, Text, " ") - 1
Do While Length > 0
word = Mid$(Text, StartPos, Length)
ReDim Preserve Array(WordCount) As String
Array(WordCount) = word
WordCount = WordCount + 1
StartPos = StartPos + Length + 1
Length = InStr(StartPos + 1, Text, " ") - StartPos
Loop
word = Mid$(Text, StartPos)
ReDim Preserve Array(WordCount) As String
Array(WordCount) = word



Where is my free box of Mr Sparkle Cleaning Detergent?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top