vb.net - add string between strings if they are not null or empty -


supossing have 4 strings want add or operator between them:

dim s1="db = 45 , frec = 500 " dim s2="db = 25 , frec = 1 " dim s3="db = 5 , frec = 2 " dim s4="db = 15 , frec = 4 " 

so

dim result = "db = 45 , frec = 500 or db = 25 , frec = 1 or db = 5 , frec = 2 or db = 15 , frec = 4" 

thw woul easy concatenating strings

dim result= s1 & " or " & s2 & " or " & s3 & " or " & s4 

however in general, of strings empty or null if concatenate empty strings

for instance s2 = ""

dim result = "db = 45 , frec = 500 or  or db = 5 , frec = 2 or db = 15 , frec = 4" 

which incorrect, thinking replace strings "or or"

 dim result = result.replace("or or", "") 

is there better approach? quick solution hard code cases guess not good

(i cannot change design of this, strings used on several other things)

in c#:

 string.join(" or ", new[] { stringa, stringb }       .where(s => !string.isnullorempty(s))); 

note work larger arrays too. add .toarray() in case you're on .net <4.0


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -