We help IT Professionals succeed at work.

join string vb.net for each

Angela4eva
Angela4eva asked
on
311 Views
Last Modified: 2014-08-27
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,
Comment
Watch Question

Kyle AbrahamsSenior .Net Developer
CERTIFIED EXPERT

Commented:
after your loop:

zetazone  = zetazone.Trim(",")

it will remove the last comma.

Author

Commented:
what about the first comma

Author

Commented:
should I be using join or concat or something?
Kyle AbrahamsSenior .Net Developer
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2007

Commented:
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

Author

Commented:
well its not an array it in for loop
CERTIFIED EXPERT
Top Expert 2007

Commented:
What is the original data type?
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

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

Author

Commented:
sirbounty ,
its string
CERTIFIED EXPERT
Top Expert 2007
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.