I have a textarea on a page which I use for receiving keywords from a user so that frequencies in text documents can be calculated.
At the moment however, if a user specifies keywords on different lines, e.g:
dale
farm
evictions
Only the server, carriage returns and line breaks are preserved. So for the three keywords above, my servlet receives:
dale
farm
evictions
What is the best way to get rid of the carriage returns and line breaks? Is it best to scan and replace them by a space which is the delimiter the page requests of the user?
Thanks
Mr Morgan.
String s1 = "mr morgan\r\nis a fool";
String s2 = s1.replaceAll("[\n\r]", " ");
System.out.println(s2);
Seems to give me what I want. Thanks to the respondents.
What have you tried so far?
You have to
explode()the text by newlines (\n):If the keywords are separated by a comma:
And for
<meta name="keywords" />you have to replace all newline characters by a commaWorking example: http://codepad.org/r0tZtXwb