none
how to add from a string to list(of String)?

    Question

  • Hello :)

    I have 

      Dim Lst As List(Of String) = New List(Of String)

    and then i have a string such that

    dim strg as string="1/22/33/567/659"

    so we can use the split command here

    But can we add this string as separate number in the Lst (I know the loop way for this, but is there any another way?)

    Friday, December 06, 2013 6:20 PM

Answers

  • When you split it, you end up with a string array, so just use ".AddRange" and add that array.

    Please call me Frank :)

    • Marked as answer by Titanium man11 Friday, December 06, 2013 7:09 PM
    Friday, December 06, 2013 6:24 PM
  • Hi

    Do you mean something like this?

            Dim Lst As List(Of String) = New List(Of String)
            Dim strg As String = "1/22/33/567/659"
            Lst.AddRange(strg.Split("/"c))
    


    Regards Les, Livingston, Scotland

    Friday, December 06, 2013 6:25 PM
  • one little question

    inthe strg.split("/"c)

    what is c?


    It designates that it's to be read as a character (as opposed to a string).

    Please call me Frank :)

    • Marked as answer by Titanium man11 Friday, December 06, 2013 7:09 PM
    Friday, December 06, 2013 6:59 PM

All replies

  • When you split it, you end up with a string array, so just use ".AddRange" and add that array.

    Please call me Frank :)

    • Marked as answer by Titanium man11 Friday, December 06, 2013 7:09 PM
    Friday, December 06, 2013 6:24 PM
  • Hi

    Do you mean something like this?

            Dim Lst As List(Of String) = New List(Of String)
            Dim strg As String = "1/22/33/567/659"
            Lst.AddRange(strg.Split("/"c))
    


    Regards Les, Livingston, Scotland

    Friday, December 06, 2013 6:25 PM
  • Hi

    Do you mean something like this?

            Dim Lst As List(Of String) = New List(Of String)
            Dim strg As String = "1/22/33/567/659"
            Lst.AddRange(strg.Split("/"c))
    


    Regards Les, Livingston, Scotland


    Exactly

    Please call me Frank :)

    Friday, December 06, 2013 6:26 PM
  • one little question

    inthe strg.split("/"c)

    what is c?

    Friday, December 06, 2013 6:57 PM
  • one little question

    inthe strg.split("/"c)

    what is c?


    It designates that it's to be read as a character (as opposed to a string).

    Please call me Frank :)

    • Marked as answer by Titanium man11 Friday, December 06, 2013 7:09 PM
    Friday, December 06, 2013 6:59 PM