0

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?

3
  • string.Join will do this for you Commented Sep 9, 2016 at 9:46
  • @Steve How do I go about implementing this? Commented Sep 9, 2016 at 9:48
  • Possible duplicate of Array.Join in .Net? Commented Sep 9, 2016 at 10:18

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Yes this works thanks. It's just a simple one line way and that's what i needed :D
1

You can use String.Join(string, IEnumerable) to concat several strings to one big string

Comments

0
For i as integer = 0 to DataSyncFiles.Length - 1
    files &= IIf(files <> "","," & filesDataSyncFiles(i),filesDataSyncFiles(i))
End For 

Isnt a simple for loop required like this?

1 Comment

Yeah, i was seeing if there was a simple one line way of achieving this. If not i would have to make a loop.

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.