Results 1 to 13 of 13
  1. #1
    sythe179's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    The internet
    Posts
    660
    Reputation
    15
    Thanks
    1,458
    My Mood
    Paranoid

    [Help] Splitting strings. [solved]

    Ok, i seem to be stuck at a wall in a program im making.
    what im stuck at is this:
    127.0.0.1:4254
    what i want to do is take the port off this string and put it into another string for use. Problem is, its got to be able to go on any IP string, not a user-set one. So its got to search for the ":" and pull anything after it off for use. First half would be nice to keep aswell.....
    tryed:
    [highlight=vb.net]
    dim ip as string = console.readline()
    dim varscip as integer = 0
    ip.split(new char, (":"{c})
    for each line in ip
    Varscip += 1
    If varscip = 2 then
    console.writeline(line)
    end if
    next
    varscip = 0
    [/highlight]
    Cant remember if that .split is correct, but should be close to what i used...
    Last edited by Jason; 04-04-2011 at 07:38 PM.

  2. #2
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by *****179 View Post
    Ok, i seem to be stuck at a wall in a program im making.
    what im stuck at is this:
    127.0.0.1:4254
    what i want to do is take the port off this string and put it into another string for use. Problem is, its got to be able to go on any IP string, not a user-set one. So its got to search for the ":" and pull anything after it off for use. First half would be nice to keep aswell.....
    tryed:
    dim ip as string = console.readline()
    dim varscip as integer = 0
    ip.split(new char, (":"{c})
    for each line in ip
    Varscip += 1
    If varscip = 2 then
    console.writeline(line)
    end if
    next
    varscip = 0

    Cant remember if that .split is correct, but should be close to what i used...
    Try something like this:

    [highlight=vb.net]
    Dim rawIPstring As String = "127.0.0.1:4254"
    Dim ipPort As String() = rawIPstring.Split(":"c)
    Dim portNumber As String = ipPort(1)
    Dim ipAddress As String = ipPort(0)
    [/highlight]

    last two variables are optional, just put them there to illustrate where the values are in the array.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  3. #3
    sythe179's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    The internet
    Posts
    660
    Reputation
    15
    Thanks
    1,458
    My Mood
    Paranoid
    Ok, test it when i can.
    btw, whats the reason my code did not work?

  4. #4
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by *****179 View Post
    Ok, test it when i can.
    btw, whats the reason my code did not work?
    ip.Split(New Char, (":"{c}))

    What is that lol?

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  5. #5
    sythe179's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    The internet
    Posts
    660
    Reputation
    15
    Thanks
    1,458
    My Mood
    Paranoid
    Thought you had to define it a bit more.....

  6. #6
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by *****179 View Post
    Thought you had to define it a bit more.....
    Look at the overloads on the Split function, I haven't opened VB in a while but I'm pretty sure there is at least the following:

    separator() as char <- character array. This means that you can split between different chars
    separator() as char, count as integer <- split about all the chars in the array, but only split the first <count> occurrence(s).
    and a few more.

    So really mine should have been:

    [highlight=vb.net]
    Dim ipPort As String() = rawIPstring.Split(New Char() {":"c})
    [/highlight]

    which would work the same. It looks like you attempted to create an array for the parameter, but fucked it up terribly

    [highlight=vb.net]
    ip.Split(New Char, (":"{c}))

    '..should be:

    ip.Split(New Char() {":"c})
    [/highlight]

    But remember that Split is a function, not a method, meaning it returns the strings so if you want the split values you must assign the result to a variable (as I did in the previous post)

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  7. The Following User Says Thank You to Jason For This Useful Post:

    sythe179 (04-05-2011)

  8. #7
    sythe179's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    The internet
    Posts
    660
    Reputation
    15
    Thanks
    1,458
    My Mood
    Paranoid
    k, ty for your help.

    /solved

  9. #8
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Marked solve, don't think there should be any reason for anyone to post further.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  10. #9
    sythe179's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    The internet
    Posts
    660
    Reputation
    15
    Thanks
    1,458
    My Mood
    Paranoid
    Found a reason....
    returns with ip being 1 and port being 2...
    console : "1;2"

  11. #10
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by *****179 View Post
    Found a reason....
    returns with ip being 1 and port being 2...
    console : "1;2"
    So change the 'split' character to a semicolon rather than a colon?

    ip.Split(New Char() {";"c})

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  12. #11
    sythe179's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    The internet
    Posts
    660
    Reputation
    15
    Thanks
    1,458
    My Mood
    Paranoid
    No, thats just a exit string i used...

  13. #12
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by *****179 View Post
    No, thats just a exit string i used...
    A what now? What is the problem?

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  14. #13
    sythe179's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    The internet
    Posts
    660
    Reputation
    15
    Thanks
    1,458
    My Mood
    Paranoid
    The problem is, its not spliting. Just taking the first and last value from the string.