trim string in java, remove white space

谁都会走 提交于 2019-12-11 10:58:54

问题


<%=CMSStringUtility.toTitleCase(attrValues.getDisplayLabel())%>

this returns a string with a leading white space character that I need to remove. I believe this is JAVA in a jsp file. I tried the following:

<%=CMSStringUtility.toTitleCase(attrValues.getDisplayLabel()).trim()%>

and

<%=CMSStringUtility.toTitleCase(attrValues.getDisplayLabel().trim())%>

I am a JSP newbie, any ideas?


回答1:


If trim() does not remove a whitespace, it means it is not in the predefined list of whitespaces. This is usually a non-breaking space (code 160). Try to iterate the toCharArray() and see the ascii code of the space.




回答2:


trim only removes leading and trailing spaces. To remove other invisible characters you may use a regular expression.



来源:https://stackoverflow.com/questions/5758324/trim-string-in-java-remove-white-space

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!