java 如何修剪字符串中的“输入键”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5090483/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 09:21:43  来源:igfitidea点击:

how to trim "enter key" in a string

javajsp

提问by Learner

String strFCKeditor1 = request.getParameter("FCKeditor1");

String strFCKeditor1 = request.getParameter("FCKeditor1");

回答by Snake

String strFCKeditor1 = request.getParameter("FCKeditor1").replaceAll("\r|\n", "");

You also need to replace the \rand/or \n\r(hence the regex), not just \nas stated in the other answer, since you don't know whether your user is using Windows / Mac OSX / Linux.

您还需要替换\r和/或\n\r(因此是正则表达式),而不仅仅是\n如其他答案中所述,因为您不知道您的用户是否使用 Windows/Mac OSX/Linux。

回答by Jigar Joshi

strFCKeditor1.replaceAll("\n","");//this will replace all \n with blank string

回答by Pushkar

From your question i assume you want to remove the newline characters from the end of your string.

从您的问题中,我假设您想从字符串的末尾删除换行符。

Use -

利用 -

StringUtils.chomp(str);

StringUtils.chomp(str);

http://commons.apache.org/lang/apidocs/src-html/org/apache/commons/lang3/StringUtils.html#line.4353

http://commons.apache.org/lang/apidocs/src-html/org/apache/commons/lang3/StringUtils.html#line.4353