[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

CSV items to multiline textbox in VB.NET

Posted on 2009-05-14
7
Medium Priority
?
853 Views
Last Modified: 2013-11-26
I am using Visual Studio 2008. I am trying to take a line of comma separated items and send them to a multiline textbox.  For example "1,2,3,4" would appear in the textbox as:

1
2
3
4

I would like to do this in a For Each or For Next statement.
0
Comment
Question by:schwientekd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 16

Expert Comment

by:Walter Ritzel
ID: 24389013
If you dont have the comma as a valid char for each value, you can try something like this:

Dim formatedValue as String

formatedValue = SourceCSVLine.Replace(",",CHR(13))

textBox.Text = formatedValue

Sorry for bad VB syntax... I'm C# guy....
0
 
LVL 8

Expert Comment

by:RyanAndres
ID: 24389106
The following code assigns each delimited part as a new line
string line = "1,2,3,4";
textBox.Text = line.Replace(',', '\n');

Open in new window

0
 
LVL 8

Expert Comment

by:RyanAndres
ID: 24389115
Someone beat me and I forgot to convert to VB:
Dim line As String = "1,2,3,4"
textBox.Text = line.Replace(","c, ControlChars.Lf)

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:schwientekd
ID: 24389128
I modified your lines slightly by replacing CHR(13) with vbCrLf and that did accomplish the simple question I asked.  However I was looking for a way to do this with a For statement.  The reason is that the thing I am trying to accomplish is much more complex but I was trying to start small.  The comma separated items I am using are actually going to be codes that are stored in a table.  Each code will have another column with a description and the descriptions are what need to appear in my textbox. Sorry for the long explanation which I don't expect to be answered in this post but I just wanted to explain my reason for wanting to use a For statement.
0
 
LVL 8

Accepted Solution

by:
RyanAndres earned 2000 total points
ID: 24389333
This code allows you to manipulate each line. If this is not what you're looking for please provide a sample input and expected output.

Dim str As String = "1,2,3,4"
Dim lines As String() = str.Split(","c)
 
Dim output As New StringBuilder()
For Each line As String In lines
    output.AppendLine(line.Trim())
Next
txtFirstName.Text = output.ToString()

Open in new window

0
 
LVL 16

Expert Comment

by:Walter Ritzel
ID: 24390580
In this case, I think the last code from RyanAndres is what you are looking for.
0
 

Author Closing Comment

by:schwientekd
ID: 31581651
I think that this will get me started.  Thanks.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

649 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