Results 1 to 10 of 10

Thread: [2008] Spliting a variable

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2007
    Posts
    520

    Cool [2008] Spliting a variable

    heya guys

    If i have a variable that is in the format of:

    Luke Frost : 1234567

    how can i get it so that the values before the ' :' are saved as one variable and the bit after ': ' is another variable?

    Thank you in advanced

    Frosty

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2008] Spliting a variable

    I assume it's a string. So you just use string.split(":"c)
    Code:
    Dim myString As String = "Luke Frost : 1234567"
    Dim parts As String() = myString.Split(":"c)
    'Now parts(0) should hold "Luke Frost " and parts(1) holds " 1234567"

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2007
    Posts
    520

    Re: [2008] Spliting a variable

    how can i then get rid of the space at the end of the 1st variable and then begining of the 2nd variable?

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2008] Spliting a variable

    .Trim() or split by " : " if it's consistent.

  5. #5
    New Member
    Join Date
    Aug 2008
    Posts
    6

    Re: [2008] Spliting a variable

    What if I had a string like AB22913 and I need to split it into
    [AB][22][9]&[13]
    Would I need to put a seperator such as ":" in there for it to work or is there another way?

  6. #6

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2008] Spliting a variable

    so you want the 1st 2 characters, the next 2 characters, the next character, then the last 2 characters?

    use the string.substring method

    vb Code:
    1. dim theString as string = "AB22913"
    2. dim var1 as string = theString.substring(0,2)
    3. dim var2 as string = theString.substring(2,2)
    4. dim var3 as string = theString.substring(4,1)
    5. dim var4 as string = theString.substring(5,2)

  8. #8
    New Member
    Join Date
    Aug 2008
    Posts
    6

    Re: [2008] Spliting a variable

    Can you be a bit clearer please. I'm a noobie.

    How can I seperate the variable without using a seperator?

    Never mind.

    Thanks Paul!

  9. #9
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2008] Spliting a variable

    What do you need to do with it afterwards? #7 shows you how to get it into separate variables.

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2008] Spliting a variable

    i think post #8 was a reply to post #6 + a thankyou for post #7

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