Link to home
Create AccountLog in
Avatar of Angela4eva
Angela4eva

asked on

join string vb.net for each

Dim zetazone as string
for each zstring as..
zetazone= zetazone&"," & zetazone
next

I am trying to cretae  comma delimited string and instead of shoing item1,item2 its showing
,item1,item2,
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

after your loop:

zetazone  = zetazone.Trim(",")

it will remove the last comma.
Avatar of Angela4eva
Angela4eva

ASKER

what about the first comma
should I be using join or concat or something?
SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
should I be using join or concat or something?
Possibly - have you tried using join?


Example:
Module Module1
    Sub Main()
      ' Three-element array.
      Dim array(2) As String
      array(0) = "Dog"
      array(1) = "Cat"
      array(2) = "Python"

      ' Join array.
      Dim result As String = String.Join(",", array)

      ' Display result.
      Console.WriteLine(result)
    End Sub
End Module
http://www.dotnetperls.com/join-vbnet
well its not an array it in for loop
What is the original data type?
You can also use LINQ for this task:

Imports System.Linq

...

Dim zetazone As String = whateverFollowsAsInYourForEach.Aggregate(Function (accumulator, iterator) accumulator + "," + iterator)

Open in new window

sirbounty ,
its string
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account