问题
<%=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