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!
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!
What kind of statement are You using? Is it Statement or PreparedStatement?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
why do you need to m,ark special characters, would appear you should be just saving the text as is.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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,replace With){
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.va lue.replac e("%0D%0A" ,replaceWi th)
}
else if(textarea.value.indexOf( "%0A") > -1){
Unix encodes returns as \n hex
textarea.value=textarea.va lue.replac e("%0A",re placeWith)
}
else if(textarea.value.indexOf( "%0D") > -1){
Macintosh encodes returns as \r hex
textarea.value=textarea.va lue.replac e("%0D",re placeWith)
}
}
textarea.value=unescape(te xtarea.val ue) unescape all other encoded characters
}
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,replace
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(
Windows encodes returns as \r\n hex
textarea.value=textarea.va
}
else if(textarea.value.indexOf(
Unix encodes returns as \n hex
textarea.value=textarea.va
}
else if(textarea.value.indexOf(
Macintosh encodes returns as \r hex
textarea.value=textarea.va
}
}
textarea.value=unescape(te
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This problem appears to have been resolved.
colr__
colr__