Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have List3 as List(Of List(Of Integer))
Dim List3 As New List(Of List(Of Integer))
Dim List1 As List(Of Integer) = {1, 2, 5, 7}.ToList
Dim List2 As List(Of Integer) = {5, 3, 2, 1}.ToList
List3.Add(List1)
List3.Add(List2)


How can i get string like this
1,2,5,7 
5,3,2,1


What I have tried:

Dim str As String = String.Join(vbNewLine, List3)
Posted
Updated 8-Oct-19 8:24am
v2

A simpler solution using LINQ:
VB.NET
Dim str As String = String.Join(vbNewLine, List3.Select(Function (list) String.Join(",", list)))
Lambda Expressions (Visual Basic) | Microsoft Docs[^]
 
Share this answer
 
Comments
Maciej Los 8-Oct-19 16:06pm    
5ed!
phil.o 8-Oct-19 17:42pm    
5'd also.
There's so much time I left VB now, generics did not exist yet; when I have to write some code block in VB, I think about it in c#, and have to go through a mental translation process. Let alone Linq... Thanks Richard.
Richard Deeming 9-Oct-19 6:48am    
Same here - I haven't done any serious VB.NET work for over 15 years. :)
gacar 10-Oct-19 7:24am    
This is! Thank you very much.
You have to iterate the collection and format the output:
VB
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text

Public Shared Function DumpListOfList(Of T)(List(Of List(Of T)) list) As String
   Dim builder As New StringBuilder()
   For Each sublist As List(Of T) In list
      builder.AppendLine(String.Join(",", sublist.ToArray()))
   Next
   builder.Remove(builder.Length - 2, 2) '' Get rid of the last CrLf
   Return builder.ToString()
End

'' Usage:
Dim result As String = DumpListOfList(List3)
 
Share this answer
 
v3
Comments
Maciej Los 8-Oct-19 16:06pm    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900