Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

To Convert a .txt file into .html file

 
Ramya Thyagarajan
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • 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?
 
James Ellis
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • 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.
 
Casper Maxwell
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • 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...
 
Karthikeyan Rajendraprasad
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just rename the .txt file to .html file... that would do. no need to have html tags
 
Geoffrey Falk
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic