Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

To Convert a .txt file into .html file

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a .txt file generated by my program but I require the contents of the file generated to be displayed in a HTML window.

Is it possible to move the contents of a .txt file into a .html file without hampering the format?
 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your browser should be able to successfully render the .txt file without needing to convert the file to html. A .txt file is about as simple as it gets and any browser built within the last 3 years should be able to handle it.
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may do the conversion like this:

Text file:

"Just try sth. Do sth.

And do sth different."

Html file:

"
<html>
<body>
<p>Just try sth. Do sth.</p>

<p>And do sth different.</p>
</body>
</html>
"

So you can add a <p> tag to each of you paragraphes(You may search for two newlines in your text to determine paragraph positions. "\n\n") and add some header(e.g. <html> and trailer (</html> tags...
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just rename the .txt file to .html file... that would do. no need to have html tags
 
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just slap an HTML header on the top of the file



Oh yeah, you'll also have to escape things like angle brackets and ampersands with their corresponding HTML escape codes.

Geoffrey
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic