?
Solved

join string vb.net for each

Posted on 2014-08-05
10
Medium Priority
?
280 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,
0
Comment
Question by:Angela4eva
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 41

Expert Comment

by:Kyle Abrahams
ID: 40242502
after your loop:

zetazone  = zetazone.Trim(",")

it will remove the last comma.
0
 

Author Comment

by:Angela4eva
ID: 40242514
what about the first comma
0
 

Author Comment

by:Angela4eva
ID: 40242515
should I be using join or concat or something?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 41

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 1000 total points
ID: 40242523
Dim zetazone as string
for each zstring as..
   zetazone = zetazone & zstring  & ","
next

zetazone = zetazone.Trim(",")
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 40242540
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
 

Author Comment

by:Angela4eva
ID: 40242573
well its not an array it in for loop
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 40242685
What is the original data type?
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40243468
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
 

Author Comment

by:Angela4eva
ID: 40243661
sirbounty ,
its string
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 1000 total points
ID: 40243758
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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…
Suggested Courses

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question