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,
ASP.NETVisual Basic.NET

Avatar of undefined
Last Comment
sirbounty

8/22/2022 - Mon
Kyle Abrahams

after your loop:

zetazone  = zetazone.Trim(",")

it will remove the last comma.
Angela4eva

ASKER
what about the first comma
Angela4eva

ASKER
should I be using join or concat or something?
Your help has saved me hundreds of hours of internet surfing.
fblack61
SOLUTION
Kyle Abrahams

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
sirbounty

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
Angela4eva

ASKER
well its not an array it in for loop
sirbounty

What is the original data type?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
kaufmed

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

Angela4eva

ASKER
sirbounty ,
its string
ASKER CERTIFIED SOLUTION
sirbounty

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.