aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes How to break up long lines? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to break up long lines?" Watch "How to break up long lines?" New topic
Author

How to break up long lines?

Sam Walker
Ranch Hand

Joined: Nov 06, 2002
Posts: 65
Hello all,
Could anyone please tell me if there is a script that I can use to break up a long line into smaller ones?
Here�s the problem I�m trying to solve. I have a textarea where a user can enter anything up to 500 characters. It�s very important that I preserve the format of whatever the user enters, because I need to show all the spacing as entered. I�m using <pre></pre> to save the format of the text along with the content of the textarea. When I display this information in another page in a table column everything looks fine except for very long lines, they show up without any wrapping instead they stretch the column width. Please note that the textarea where this information is initially entered does wrap long lines.
The only way I can see around this is to break up a long line into shorter ones.
Thanks very much for your advice
Chris Baron
Ranch Hand

Joined: Mar 21, 2003
Posts: 1049
Hi Sam,
if you use JSP this example might be helpful:

The Syntax of method "txt2html" as a JavaScript function is almost identical.
[ June 17, 2003: Message edited by: Chris Baron ]
[ June 17, 2003: Message edited by: Chris Baron ]
Sam Walker
Ranch Hand

Joined: Nov 06, 2002
Posts: 65
Hi Chris,
Thanks for the script but my problem is that the user can enter a line up 500 characters without any �\n� until the very end. If my user enters something like the following I can display it back with all spaces preserved exactly as it appears without any problem as long as I enclose the text within <pre></pre> tags.


But in case of a long unbroken block of text like the following <pre></pre> make the text appear as one long line.
The J2EE platform provides two types of server-side components for generating dynamic content: servlets and JavaServer PagesTM (JSPTM pages). Servlets are Java classes that generate dynamic content by writing it directly to an output stream. JSP pages are structured static content (such as HTML or XML) interspersed with either Java code ("scriptlets") or custom tags that produce dynamic content. JSP pages and servlets are mapped to URLs in a Web server's name space. The servlet or JSP page produces dynamic content in response to a client making a request to its URL.

Also this problem shows up not on the original textarea but after I save what the user enters and try to display it again in a table column.
[ June 17, 2003: Message edited by: Sam Walker ]
[ June 17, 2003: Message edited by: Sam Walker ]
Chris Baron
Ranch Hand

Joined: Mar 21, 2003
Posts: 1049
Hi Sam,
i think my example does exactly what you discribe.
It replaces all \n from the Textarea with html <br/>. And as html only displays one blank in a row every second blank is replaced by the html escape-characters &nbsp;. If there's a long unbroken block, it is forced to the width of 300px in the <p> in my example. The text is displayed like in the textarea.
Do you use JSP or something else ?
Sam Walker
Ranch Hand

Joined: Nov 06, 2002
Posts: 65
Chris,
That�s great thank you very much. I am using both JSP and JavaScript but I�ll plug in the code in a JSP file just as you have it.
Thanks a lot again I�ve been looking at this problem for a while and I was convinced I would have to write something to break up the line.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to break up long lines?