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,
Angela4evaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
after your loop:

zetazone  = zetazone.Trim(",")

it will remove the last comma.
0
Angela4evaAuthor Commented:
what about the first comma
0
Angela4evaAuthor Commented:
should I be using join or concat or something?
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Kyle AbrahamsSenior .Net DeveloperCommented:
Dim zetazone as string
for each zstring as..
   zetazone = zetazone & zstring  & ","
next

zetazone = zetazone.Trim(",")
0
sirbountyCommented:
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
0
Angela4evaAuthor Commented:
well its not an array it in for loop
0
sirbountyCommented:
What is the original data type?
0
käµfm³d 👽Commented:
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

0
Angela4evaAuthor Commented:
sirbounty ,
its string
0
sirbountyCommented:
Not knowing how you're code is setup and how you're populating that string, this works for me:

Dim zetazone as string() = "abc def ghi".split(" ") 'whatever string array element you have
Dim zString as string = string.join(",",zetazone)
debug.print zString returns
"abc,def,ghi"

If I'm not tracking with you, can you let me know how you're populating zetazone?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.