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,
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,
ASKER
what about the first comma
ASKER
should I be using join or concat or something?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
ASKER
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)
ASKER
sirbounty ,
its string
its string
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
zetazone = zetazone.Trim(",")
it will remove the last comma.