|
-
Sep 28th, 2000, 03:19 PM
#1
Thread Starter
Hyperactive Member
OK here is the situation. I am working on a program
where I pull a word from a .txt file, (for this question, let's say the word is "TABLE". I want my prog to seperate each individual letters..T A B L E... and set them into a string array.
Like this...
dim strName(4) as string.
therefore the word table would kick out...
strName(0) = T
strName(1) = A
strName(2) = B
strName(3) = L
strName(4) = E
Now I think I use the Split function, however...I have no clue of the syntax for this...HELP!
Thanks!
Lee
 Mahalo 
VB6(SP5), VC++, COBOL, Basic, JAVA
MBA, MCSD, MCSE, A+
Computer Forensics
-
Sep 28th, 2000, 03:31 PM
#2
Lively Member
Here is what I would do
Code:
Dim strString As String
Dim strName() As String * 1
Private Sub Object_Event()
strString = "Table"
ReDim strName(Len(strString))
Dim iCount As Integer
For iCount = 0 To Len(strString) - 1
strName(iCount) = Mid(strString, iCount + 1, 1)
Next
End Sub
-
Sep 28th, 2000, 03:34 PM
#3
Thread Starter
Hyperactive Member
Thanks, I wanted to learn the Split function, I thought it might be an easier way, rather than hard coding the instructions myself. Thanks for the input though!!!
 Mahalo 
VB6(SP5), VC++, COBOL, Basic, JAVA
MBA, MCSD, MCSE, A+
Computer Forensics
-
Sep 28th, 2000, 03:46 PM
#4
Lively Member
Oh, {blush}, my bad
I think you have to have a delimeter for the Split function. For example, if the string read in as T.A.B.L.E. Then you could use the period as the delimeter as in the following code.
Code:
Dim strString As String
Dim strName() As String
Private Sub Object_Event()
strString = "T.A.B.L.E"
strName = Split(strString, ".")
End Sub
-
Sep 28th, 2000, 03:49 PM
#5
Thread Starter
Hyperactive Member
Ok OK I see, so if I was loading the strings from a txtFile then every entry in the file would have to be seperared by a "." That should be OK!
Thanks!
Lee
 Mahalo 
VB6(SP5), VC++, COBOL, Basic, JAVA
MBA, MCSD, MCSE, A+
Computer Forensics
-
Sep 28th, 2000, 03:52 PM
#6
Lively Member
yeah you got it. It can be any delimeter, not just the period. but you would change the split line to whatever the delimeter was like Split(string, "-") where - is the delimeter.
-
Sep 28th, 2000, 04:31 PM
#7
Hyperactive Member
The easiest way that I can think of though to get a string into an array for quick processing (as long as you are looking at a single byte [letter] at a time) is using a bytearray.
Code:
Dim b() as byte
b() = yourstringgoeshere
-
Sep 28th, 2000, 05:29 PM
#8
Thread Starter
Hyperactive Member
OK so if your string was a word say "Table"
if you set it in a byte array, like say
Dim b(4) as byte
b = "table"
would that mean that
b(0) = T
b(1)= a
b(2) = b
b(3) = l
b(4) = e
????? I like the logic, but I can't see this flying
Lee
 Mahalo 
VB6(SP5), VC++, COBOL, Basic, JAVA
MBA, MCSD, MCSE, A+
Computer Forensics
-
Sep 28th, 2000, 06:30 PM
#9
Lively Member
Well, Acutally
I just tried the following code and was quite suprised with the results.
Code:
Dim strString As String
Dim strName() As Byte
Private Sub Form_Load()
strString = "TABLE"
ReDim strName(Len(strString) - 1)
strName() = strString
End Sub
the result was this
strName(0) = 84
strName(1) = 0
strName(2) = 65
strName(3) = 0
strName(4) = 66
Which when you use the Chr() they are T A B. I don't know why it was making every other character a 0? but it does seem to work sorta. Does anyone else know what is the deal with every other element being "0"?
Oops, made a typo. I do that. the point was if I had not limited the number of elements by the string width it would have put the entire word TABLE in the array letter by letter but it would have also put a "0" in every other element.
[Edited by KillemAll on 09-29-2000 at 09:45 AM]
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
|