• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to break up long lines?

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic