Ben Clarke Ben Clarke - 2 months ago 10
Vb.net Question

How to join strings from a list together in one string?

Issue






I have a list of strings which could be anything from 1 to 25 strings long. I want to get the values off each index and add them a string so that I can send an email listing the values in the list.

Here is the list of strings:

Dim DataSyncFiles As List(Of String) = {"COPOR1P", "FFBIVDP", "FFCHLDP", "FFDBKDP", "FFDREQP", "FFINVHP", "FFJACCP", "FFJACPP", "FFJMNEP", "FFJOBSP", "FFPIVHP", "FFUNTTP", "FJBJB1P", "FJBJM1P", "FJBJM2P", "FJBJU1P", "FJBNT2P", "FPPBE9P", "FSANO1P", "FTPCP1P", "FTTEG1P", "FTTEO1P", "FTTRQ1P", "XATXTDP", "FFADDRP", "FFLOCNP"}.ToList()


So i want to loop through these and add them to one single string (string below). The list above is not always going to be 26 strings long.

Dim files as string


How am i best to do this?

Answer

It is a simple string.Join

fileList = string.Join("", DataSyncFiles)

The first parameter is the separator to use between the single elements of DataSyncFiles. If you don't need it just pass an empty string or Nothing