0

Hey I am making a String but some of thevariables are going to be empty and I want these to be skipped but not sure how to go about this. Here is the code for the string below.

Dim TenantList As String = Ten11 & "," & Ten10 & "," & Ten9 & "," & Ten8 & "," & Ten7 & "," & Ten6 & "," & Ten5 & "," & Ten4 & "," & Ten3 & "," & Ten2 & "," & Ten1

1 Answer 1

3

You can put them in a collection and use String.Join:

Dim allStrings As String() = {Ten11, Ten12, Ten13, Ten14, ...}
Dim notEmpty = From str In allStrings Where Not String.IsNullOrEmpty(str)
Dim TenantList As String = String.Join(",", notEmpty)

I'm using LINQ to filter out the empty strings, so you need Imports System.Linq.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.