• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is wrong with my code? trouble extracting input from Textarea

 
Stephen Wei
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all, I want my servlet to extract the input from the textarea, then remove all the new line characters, not working well, what is wrong? Can someone help please?
Here is what it looks like:
String temp = request.getParameter(textareaName);
//assume temp is not null.
StringTokenizer st = new StringTokenizer(temp, "\n", false);
StringBuffer buffer = new StringBuffer("");
while(st.hasMoreTokens()){
buffer.append(st.nextToken());
}
String filtered = buffer.toString();
//insert filtered into DB
With the above code, when I extract the string from the DB and read it by excel, it keep returning newline, what is wrong?
Is there something special reading text from Textarea? Can I remove the new line by adding "WRAP = virtual, or WRAP=soft"? But IE and NS use different value for WRAP attribute, I guess I can not satisfy both browsers at the same time...
Please help.
THanks
 
Jayson Chacko
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this
new StringTokenizer(temp, "\n\r", false);
I think "\r" is also can come as newline.
 
Stephen Wei
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THanks Jayson!
It worked for me, solved my problem.
It was so cool!
JavaRanch is certainly great, I solved many problems here, keep coming!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic