Results 1 to 4 of 4

Thread: Split a string on certain poitions.

  1. #1

    Thread Starter
    Hyperactive Member Tequila_worm's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    344

    Split a string on certain poitions.

    I'm trying to split a string on certain positions such as the following code.

    VB Code:
    1. dim catID, parID
    2.  
    3. catID = 3
    4. parID = "1a1a11a1"
    5.  
    6. dim intX =  0 to catID
    7.   if intX = 0 then
    8.      'Grab the numbers from the first a and all numbers before it
    9.      'the one before the first a can also be a numbers like 243a
    10.   if intX = 1 then
    11.      'Go to the second a, don't grab the a but grab everything before it.
    12.   if intX = 2 then
    13.      'Go to the third a and don't grab the a but grab everything before it.
    14. next


    Please if anyone could help with this it would mean the world to me. I've been stressing over this for days , thanks alot for the help guys/girld.

    Ed.

  2. #2
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Use the SPLIT function as follows:

    arString =split ("1a111a1111a111111111111","a") ->


    gives:
    arString(0) = "1"
    arString(1) = "111"
    arString(2) = "1111"
    arstring(3) = "1a111a1111a111111111111"


    it spilts the string u give it into parts based on a delimiter. In this example i told it 'a' was the delimiter and so it breaks it up into its component parts and stores each element in an array called arString
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  3. #3

    Thread Starter
    Hyperactive Member Tequila_worm's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    344
    Originally posted by Blobby
    Use the SPLIT function as follows:

    arString =split ("1a111a1111a111111111111","a") ->


    the following should actually be

    gives:
    arString(0) = "1" ------------------> "1a"
    arString(1) = "111" ---------------> "1a111a"
    arString(2) = "1111" -------------> "1a111a1111a"
    arstring(3) = "1a111a1111a111111111111"


    it spilts the string u give it into parts based on a delimiter. In this example i told it 'a' was the delimiter and so it breaks it up into its component parts and stores each element in an array called arString
    i was trying with the split the problem here is i need them to also grab the a's before. so for your result should be such as i fixed them on top, thank's a millin for the response, i apreciate it.

    Any help would be greatfully apreciated thanks again.

    Ed.

  4. #4
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Create a form with a default textbox and a command button
    providing the last character is an 'a' it will return as you want it to.

    so 1a111a1111a will give:

    1a
    1a111a
    1a111a1111a

    but

    1a111a1111 will give just:

    1a
    1a111a

    so if you want the last field even tho it doesnt end in an 'a' just amend an a to the end of the input string (text1.text) if it hasnt got one

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim a As Integer
    3.  
    4. a = 0
    5. position = 1
    6. While a = 0
    7.      position = InStr(position, Text1.Text, "a")
    8.      If position = 0 Then
    9.         a = 1
    10.     Else
    11.      MsgBox Left(Text1.Text, position)
    12.      position = position + 1
    13.     End If
    14. Wend
    15.  
    16. End Sub
    Last edited by Blobby; Jan 11th, 2003 at 11:22 AM.
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

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