1

Hello everyone I don't know how I can put the values I get from the list into String() format.

This is my current code:

 Private files As String()
files = New String() {
            "00", "01", "02", "03", "04", "05", "06", "07",
            "08", "09", "0A", "0B", "0C", "0D", "0E", "0F",
            "10", "11", "12", "13", "14", "15", "16", "17",
            "18", "19", "1A", "1B", "1C", "1D", "1E", "1F",
            "20", "21", "22", "23", "24", "25", "26", "27",
            "28", "29", "2A", "2B", "2C", "2D", "2E", "2F",
            "30", "31"}

Dim vals As New List(Of String)()
        Dim Counter As Integer
        For Counter = 1 To 5
            vals.Add(Counter.ToString)
        Next

        files = String.Join(",", vals) 'I'm getting an error here that I can't convert String to String ()

I want to finally bob this result: files = new String() {"1","2","3","4","5"}

Thank you all for your help

6
  • String.Join returns a String. vals is already a List(Of String). Maybe you want .ToArray(). Or what do you want? Commented Feb 21, 2020 at 13:32
  • @mm8 yes it is clear to me that String.Join returns a string, how can I return ToArray()? Commented Feb 21, 2020 at 13:34
  • @mm8 I have a values values Counter.Tostring(), is it possible for this part to take values in a string? LIKE: files = Enumerable.Range(1.tostring(), 5.tostring()).toArray() Commented Feb 21, 2020 at 13:41
  • I am not sure I follow. Enumerable.Range accepts two Integers. It doesn't accept strings. Commented Feb 21, 2020 at 13:45
  • @mm8 so yes i'm clear but with me the files string () as I stated in the question and in your answer is files = integer Commented Feb 21, 2020 at 13:46

1 Answer 1

2

String.Join returns a String. vals is already a List(Of String)...

If you want a String(), you can just convert the list to an array:

files = vals.ToArray()

...or avoid creating the list in the first place:

files = Enumerable.Range(1, 5).Select(Function(x) x.ToString).ToArray()
Sign up to request clarification or add additional context in comments.

1 Comment

@Mara You can also do a similar thing with that hex array Dim files = Enumerable.Range(0, 50).Select(Function(x) x.ToString("X2")).ToArray()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.