|
-
October 22nd, 1999, 09:10 AM
#1
How do I Take a large string and divide it up into smaller ones?
What is the best way to take a large string like a line of text read from a file and break it up into smaller chunks. For example if I had the following txt file parts (not all of the strings are the same size)
The text file would look like:
Hi My name Is Dork
What Kinda Name Is That Moron
Now I want to take this file and read in the lines and divide the individual lines up into individual strings like this:
a = Hi
b = My
c = Name
d = Is
e = Dork
a = What
b = kinda
c = Name
d = Is
e = That
f = Moron
Perhaps this could be in an array?!?
Thanks,
Aaron
-
October 22nd, 1999, 09:56 AM
#2
Re: How do I Take a large string and divide it up into smaller ones?
the function you search is :
Mid(string, start[, length])
the rest :
read the string
search for space
split the string
and yes an array makes things easier
-
October 22nd, 1999, 11:31 AM
#3
Re: How do I Take a large string and divide it up into smaller ones?
If you have VB6 you can use the Split Function to Split the Text up Automatically into an Array of Individual Words, eg.
Dim sLines as Variant
sLines = Split(sText, " ")
If you don't have VB6, here's a Function to do the Same thing:
Function SplitText(byval sText as string, byval sSeperator as string) as Variant
Dim sLines() as string
Dim iLine as Long
While InStr(sText, sSeperator)
ReDim Preserve sLines(iLine)
sLines(iLine) = Left(sText, InStr(sText, sSeperator) - 1)
sText = mid(sText, len(sLines(iLine)) + (len(sSeperator) + 1))
iLine = iLine + 1
Wend
If len(sText) then
ReDim Preserve sLines(iLine)
sLines(iLine) = sText
End If
SplitText = sLines
End Function
You call it in the Same way as Split, eg.
sLines = SplitText(sText, " ")
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
October 23rd, 1999, 05:43 AM
#4
Re: How do I Take a large string and divide it up into smaller ones?
After getting the words as Aaron Young says, store the strings in a "Collection" if the number of words is not known beforehand. You can also use the "ReDim" and "Preserve" statements if you are going to use an array. However, a "Collection" is preferable.
-
October 23rd, 1999, 09:07 AM
#5
Re: How do I Take a large string and divide it up into smaller ones?
OK.. so it split up the words. How do you get the words it split up. I can't get it to work.
Thanks
-Erik
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|