开发者

how to trim "enter key" in a string

开发者 https://www.devze.com 2023-02-12 16:40 出处:网络
String strFCKeditor1 = request.开发者_Python百科getParameter(\"FCKeditor1\");String strFCKeditor1 = request.getParameter(\"FCKeditor1\").replaceAll(\"\\\\r|\\\\n\", \"\");

String strFCKeditor1 = request.开发者_Python百科getParameter("FCKeditor1");


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

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


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


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

Use -

StringUtils.chomp(str);

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

0

精彩评论

暂无评论...
验证码 换一张
取 消