解析服务器上的 HTML 文本区域的内容
我在页面上有一个文本区域,用于接收来自用户的关键字,以便可以计算文本文档中的频率。
然而,目前,如果用户在不同的行上指定关键字,例如:
dale
farm
evictions
仅保留服务器、回车符和换行符。因此,对于上面的三个关键字,我的 servlet 收到:
dale
farm
evictions
摆脱回车符和换行符的最佳方法是什么?是否最好扫描它们并用空格替换它们,该空格是用户页面请求的分隔符?
谢谢
摩根先生。
String s1 = "mr morgan\r\nis a fool";
String s2 = s1.replaceAll("[\n\r]", " ");
System.out.println(s2);
似乎给了我我想要的。感谢受访者。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
到目前为止你尝试过什么?
您必须
explode()
换行符文本 (< code>\n):如果关键字由逗号分隔:
对于
您必须用逗号替换所有
换行符示例:http://codepad.org/r0tZtXwb
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