Results 1 to 9 of 9

Thread: working with strings

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360

    Angry

    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

  2. #2
    Lively Member
    Join Date
    Sep 2000
    Location
    NC, USA
    Posts
    102

    Talking 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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360

    Talking

    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

  4. #4
    Lively Member
    Join Date
    Sep 2000
    Location
    NC, USA
    Posts
    102

    Lightbulb 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

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360

    Wink

    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

  6. #6
    Lively Member
    Join Date
    Sep 2000
    Location
    NC, USA
    Posts
    102

    Thumbs up

    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.

  7. #7
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    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

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360

    Lightbulb

    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

  9. #9
    Lively Member
    Join Date
    Sep 2000
    Location
    NC, USA
    Posts
    102

    Talking 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
  •  



Click Here to Expand Forum to Full Width