Results 1 to 9 of 9

Thread: String to Array

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Lightbulb String to Array

    Hi,

    Im kinda stuck on a thing ...

    Im having a var containing a string :

    Code:
    Dim Categ As String = "Rugby,NFL,Football,ecc"
    What i need to do is to add the string from Categ string in each separate array :

    my.categories = {"Rugby", "NFL", "Football", "ecc"}


    Is there a way of doing this having in mind that some times Categ could have only 2 words, sometimes 10 words...


    Any help would be greately appreciated...

    Cheers!
    Thanks for helping me out.

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: String to Array

    Well you could start with this:-
    vbnet Code:
    1. '
    2.         Dim Categ As String = "Rugby,NFL,Football,ecc"
    3.         Dim CategArray As String() = Categ.Split(","c)

    The above separates each of the sports into separate elements in one array.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: String to Array

    Yes, thanks.

    And then getting the data back with :
    String.Join(", ", CategArray.ToArray)

    Now the main problem remains how to add all the random arrays into this shape :

    my.categories = {"Rugby", "NFL", "Football", "ecc"}

    or

    my.categories = {"Rugby", "NFL", "Football", "Soccer", "Cricket"}

    This is what confuses me the most
    Thanks for helping me out.

  4. #4
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: String to Array

    You've lost me. What random arrays ? What shape ?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: String to Array

    dim c as string = "Rugby,NFL,Football,ecc" ' could have more words ... one, two, twenty, ecc

    Dim Categ As String = c

    so now i need to split the Categ string into arrays and then put them in the following code ... depending on how many words i have to put:

    my.categories = {"Rugby", "NFL", "Football", "ecc"}



    Sometimes it could be :
    dim c as string = "Rugby,NFL,Football,Soccer,Cricket"

    Dim Categ As String = c
    my.categories = {"Rugby", "NFL", "Football", "Soccer", "Cricket"}
    Thanks for helping me out.

  6. #6
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: String to Array

    Quote Originally Posted by Niya View Post
    You've lost me.
    this
    What are you trying to do? Maybe start by explaining that.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: String to Array

    Yeah, that isn't any more clear. If my.categories is an array, then there isn't much point of breaking it up the way you are, since Split is already giving you an array. The {} notation is just a way to initialize an array with a set of values, but since you already have the array from Split, you don't need to initialize it.
    My usual boring signature: Nothing

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: String to Array

    maybe in the something like this but in vbnet:

    Code:
    $content['custom_fields'] = array(
            array('key' => 'cricket', 'value' => true),
            array('key' => 'football', 'value' => true),
            array('key' => 'soccer', 'value' => true),
        );
    Thanks for helping me out.

  9. #9
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: String to Array

    Does your brain comprehend we have no idea what my.categories even is? at what point has this entered our lives. You might get some solid help if you actually took the time to explain in DETAIL.
    My Github - 1d3nt

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