Link to home
Start Free TrialLog in
Avatar of LepreRossa
LepreRossa

asked on

Read a text and formatt it

I want to read a text from a text area and store it in a DB. My problem is : how can I do to format my text before store it in db.
For example if I tape this text in my text area:

"The sun was shining on the sea,
Shining with all his might:
He did his very best to make
The billows smooth and bright-
And this was odd because it was
The middle of the night."

how read the carriage return and marked them with a special character?
And when I get my text from db to a txt file, how formatting it and have a text like over.  

Thnks!
Avatar of StillUnAware
StillUnAware
Flag of Lithuania image

What kind of statement are You using? Is it Statement or PreparedStatement?
ASKER CERTIFIED SOLUTION
Avatar of hoomanv
hoomanv
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
why do you need to m,ark special characters, would appear you should be just saving the text as is.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LepreRossa
LepreRossa

ASKER

Sorry,
but I have explained badly my problem.
I would replace carriage returns with a personal tag like :"\nt" when I read my text from a jsp and then I would to replace my special tag "\nt" with carriage return when diplay my text on jsp.
I have found this function that works on client side, I need something like this but on sever side:

function escapeVal(textarea,replaceWith){
textarea is reference to that object, replaceWith is string that will replace the encoded return
textarea.value = escape(textarea.value) encode textarea string's carriage returns

for(i=0; i<textarea.value.length; i++){
loop through string, replacing carriage return encoding with HTML break tag

if(textarea.value.indexOf("%0D%0A") > -1){
Windows encodes returns as \r\n hex
textarea.value=textarea.value.replace("%0D%0A",replaceWith)
}
else if(textarea.value.indexOf("%0A") > -1){
Unix encodes returns as \n hex
textarea.value=textarea.value.replace("%0A",replaceWith)
}
else if(textarea.value.indexOf("%0D") > -1){
Macintosh encodes returns as \r hex
textarea.value=textarea.value.replace("%0D",replaceWith)
}

}

textarea.value=unescape(textarea.value) unescape all other encoded characters
}
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This problem appears to have been resolved.

colr__