473,480 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ReadToEnd line breaks

13 New Member
I am trying to read from a .txt but when it reads, all of the lines are in a single string. all I want it to do is add a break after each line. Here is the code I am using right now...

If System.IO.File.Exists("CartP.txt") Then
viewProduct = System.IO.File.OpenText("CartP.txt")
cartProduct = viewProduct.ReadToEnd()
lblProduct.Text = cartProduct
viewProduct.Close()
Else
lblProduct.Text = "There are no items in your cart."
End If

I have tried to do a ReadLine but I don't know what to do because the txt can have any given number of lines.

Thanks for you help,
You local friendly newb
May 10 '07 #1
5 3431
TRScheel
638 Recognized Expert Contributor
I am trying to read from a .txt but when it reads, all of the lines are in a single string. all I want it to do is add a break after each line. Here is the code I am using right now...

If System.IO.File.Exists("CartP.txt") Then
viewProduct = System.IO.File.OpenText("CartP.txt")
cartProduct = viewProduct.ReadToEnd()
lblProduct.Text = cartProduct
viewProduct.Close()
Else
lblProduct.Text = "There are no items in your cart."
End If

I have tried to do a ReadLine but I don't know what to do because the txt can have any given number of lines.

Thanks for you help,
You local friendly newb
Try this...

Expand|Select|Wrap|Line Numbers
  1. Dim SReader As System.IO.StreamReader = New System.IO.StreamReader(location)
  2.  
  3.         While Not (SReader.EndOfStream = True)
  4.             SReader.ReadLine()
  5.         End While
May 10 '07 #2
dscreation
13 New Member
Try this...

Expand|Select|Wrap|Line Numbers
  1. Dim SReader As System.IO.StreamReader = New System.IO.StreamReader(location)
  2.  
  3.         While Not (SReader.EndOfStream = True)
  4.             SReader.ReadLine()
  5.         End While

I can see that works, how can I display the read on a lable?
May 11 '07 #3
TRScheel
638 Recognized Expert Contributor
I can see that works, how can I display the read on a lable?
Doing this will give you a string with the contents of the file.
Expand|Select|Wrap|Line Numbers
  1. Dim SReader As System.IO.StreamReader = New System.IO.StreamReader(location)
  2. Dim MyString as String = String.Empty
  3. While Not (SReader.EndOfStream = True)
  4.      MyString = MyString + SReader.ReadLine()
  5. End While
  6.  
You could then do something like
Expand|Select|Wrap|Line Numbers
  1. MyLabel.Text = MyString
May 15 '07 #4
Killer42
8,435 Recognized Expert Expert
You might need to insert linebreaks between lines.
May 16 '07 #5
TRScheel
638 Recognized Expert Contributor
You might need to insert linebreaks between lines.

true, so do something like

mystring = SReader.ReadLine() + Environment.NewLine
May 16 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

12
3259
by: dan glenn | last post by:
Hi. I'm finding that if I have text entered into a <textarea ...> </textarea> in a form, and that text has leading blank lines (with no spaces or anything else), that when I retrieve the entered...
1
2652
by: Bill | last post by:
I am downloading data from a website that displays it in a table $fp = fopen("a website page", 'r'); The following accesses the stream one <td> element at a time $myData = fgets($fp); Then I...
6
62943
by: Jonathan | last post by:
I want to save textarea contents to a mysql database with the paragraph breaks intact without having to type paragraph or break tags in HTML. How can I do that. So far, although it occurs naturally...
4
22724
by: intl04 | last post by:
I have a memo field that is included in some Access reports I created. Is there some way for the memo field to display nicely formatted text, with line breaks between paragraphs? Or is it necessary...
2
13182
by: Mike | last post by:
I need my textbox to work more smoothly with respect to line breaks. When I have data pulled from the database into a textbox there are hard line breaks at the end of each line (by definition how...
5
16820
by: joelbyrd | last post by:
Didn't know exactly where to post this, but: How do I get line breaks in a textarea? I'm pulling text from a database, and this text definately has line breaks in it, because I replaced all the...
2
26423
by: caspardh | last post by:
i was trying to code a morse code decipherer which workd fine except that the .txt file that i was converting had linebreaks built in, i cant get python to ignore the line breaks and i cant find any...
8
2478
by: Harris Kosmidis | last post by:
It seems I cannot understand CSS, well. I have donw the following page: http://www.pennias.gr/home.php It's in greek but the context is of no importance. I used a big table to put in my page...
1
1925
by: =?ISO-8859-1?Q?thib=B4?= | last post by:
Hi, Taking a closer look to highlight_file() lastly, I found out that its line break policy was a bit.. strange. <?php # highlight_file() line breaks test $f = fopen('highlight_file_test',...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7084
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6739
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5337
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
181
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.