Results 1 to 15 of 15

Thread: VB "explode"

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    212

    VB "explode"

    Im not sure if anyone here knows PHP, but there is a command called "explode" to break apart a string. Is there any thing similar to this in Visual Basic?

  2. #2
    Fanatic Member bgmacaw's Avatar
    Join Date
    Mar 2007
    Location
    Atlanta, GA USA
    Posts
    524

    Re: VB "explode"

    The Split command is what you're looking for.

  3. #3
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: VB "explode"

    Depends on the end goal. If you need to break it apart by a delimiter, than use the Split() function. You could also use the .ToCharArray() function to break it apart into a string array, each member containing one character of the string.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    212

    Re: VB "explode"

    my goal is to take the output of a shell command and use only certain parts of it

    Would i use split() for that?

    and by the way, its going to need to be broken apart by spaces.

  5. #5
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: VB "explode"

    Then yes. Bring it in as a string. I'll call it myStr. Then run this command:
    Dim strArray() As String = myStr.Split(" ")

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    212

    Re: VB "explode"

    then when i want to retrieve it, what variable would i use?

  7. #7
    Fanatic Member bgmacaw's Avatar
    Join Date
    Mar 2007
    Location
    Atlanta, GA USA
    Posts
    524

    Re: VB "explode"

    Split would work for that, depending on if the return string had consistant delimiters. You could also use the regular expression component if your parsing needs were more complex.

  8. #8
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: VB "explode"

    You would call strArray and whatever element you want. So if you wanted the second element, you'd call for strArray(1), since arrays are 0-based.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    212

    Re: VB "explode"

    ok. thanks a lot for the quick replies, ill try that when i get back home and reply whether it worked or not.

    I guess its very similar to PHP

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    212

    Re: VB "explode"

    one more thing,

    the string that i want to break apart would be set equal to StrArray(), right?

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VB "explode"

    Yes, and its elements would be strArray(0) to strArray(x) depending on how many elements it had.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    212

    Re: VB "explode"

    Ok, thanks a lot guys

  13. #13
    New Member
    Join Date
    Oct 2007
    Posts
    5

    Re: VB "explode"

    I am trying to parse a string who's delimiter is a newline. Do you know how I could do this in VBScript?

    Thanks in advance!!

  14. #14
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: VB "explode"

    Quote Originally Posted by chankew
    I am trying to parse a string who's delimiter is a newline. Do you know how I could do this in VBScript?

    Thanks in advance!!
    This is a VB.NET forum, not VBScript. If you take a look at the site home page it tells you what each forum is for. There is one dedicated to VBScript and this is not it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  15. #15
    New Member
    Join Date
    Feb 2010
    Posts
    3

    Question Re: VB "explode"

    I want to split a string on basis of a repeated string, or may be a delimiter composed of more than one characters.

    Is there any function available to do that.

    Substring is also a function but it takes integer index values which is not applicable to my case?

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