Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

format of txt file lost

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
doomsday123@gmail.com - 24 Sep 2007 17:18 GMT
I have a txt file that I am reading and displaying on a page. The text
in the txt is...
------------------------------------------------------------------------------------------
Discontinued P/N                  Replacement P/N
71-TNPW0603100KBEBD      71-TNPW0603100KBETY
71-TNPW0603100RBEBD      71-TNPW0603100RBETY
71-TNPW0603105KBEBD      71-TNPW0603105KBETY
------------------------------------------------------------------------------------------

When I use this method to display the text on a page...
------------------------------------------------------------------------------------------
       StreamReader fsText = fi.OpenText();

       StringBuilder sb = new StringBuilder();

       while (!fsText.EndOfStream)
       {
           sb.Append(fsText.ReadLine() + "<br />");
       }
------------------------------------------------------------------------------------------

The text comes out like this...
------------------------------------------------------------------------------------------
Discontinued P/N Replacement P/N
71-TNPW0603100KBEBD 71-TNPW0603100KBETY
71-TNPW0603100RBEBD 71-TNPW0603100RBETY
71-TNPW0603105KBEBD 71-TNPW0603105KBETY
------------------------------------------------------------------------------------------

Is there any way to get the text to display exactly like it is in the
txt file?
Thanks
mpetrotta@gmail.com - 24 Sep 2007 17:36 GMT
On Sep 24, 9:18 am, "doomsday...@gmail.com" <doomsday...@gmail.com>
wrote:
> I have a txt file that I am reading and displaying on a page. The text
> in the txt is...
[quoted text clipped - 28 lines]
> txt file?
> Thanks

It looks like you're creating an HTML file.  If you open the HTML file
in a text editor, you'll see that the spaces are there as expected.
The culprit here is your browser, collapsing multiple spaces to a
single space.  See http://www.sightspecific.com/~mosh/WWW_FAQ/nbsp.html
for more information.

What can you do?  You can substitute, as the page above discusses, a
&nbsp for a space.  Or you can substitute it only when you see
multiple spaces in sequence.  Or you can convert the formatted table
to a proper HTML table, if possible.

This is an HTML issue, not a C# one, so you may get more help in an
HTML newsgroup.

Michael
Nicholas Paldino [.NET/C# MVP] - 24 Sep 2007 17:55 GMT
Using &nbsp to replace the spaces is indeed the correct way to go.  In
order to do it on the server side, you can call the HtmlEncode method on the
HttpServerUtility instance exposed by the page you are on (through the
Server property).  This will take a string and return an HTML-encoded
string, or you can write it to a TextWriter if you want.

   It should be noted that this isn't a "problem" with the browser, but
rather, the way HTML is supposed to behave, this is ^expected^ behavior.

   On the browser side, you are most likely going to want to use a
fixed-width font for the presentation of this data, as spaces in
non-fixed-width fonts usually tend to be small, and you won't have that much
space between them.

   Either that, or as Michael says, use tables to perform the layout (which
would require more parsing on your end).

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> On Sep 24, 9:18 am, "doomsday...@gmail.com" <doomsday...@gmail.com>
> wrote:
[quoted text clipped - 46 lines]
>
> Michael

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.