문제

The answer to Java escape HTML shows StringUtils.replaceEach() which runs similar to multiple StringUtils.replace()s, but accepting arrays of Strings instead of having to do each replace individually.

For example:

str = StringUtils.replace(str, "&", "&");
str = StringUtils.replace(str, "\"", """);
str = StringUtils.replace(str, "<", "&lt;");
str = StringUtils.replace(str, ">", "&gt;");

...becomes...

str = StringUtils.replaceEach(str,
    new String[]{"&", "\"", "<", ">"},
    new String[]{"&amp;", "&quot;", "&lt;", "&gt;"})

Much cleaner.

Where can I access StringUtils.replace()?

I have tried importing the following, to no avail:

  1. org.springframework.util.StringUtils
  2. org.apache.soap.util.StringUtils
  3. org.apache.axis.utils.StringUtils
  4. com.ibm.wsdl.util.StringUtils

They each have .replace(), of course.

도움이 되었습니까?

해결책

It believe you are looking for: org.apache.commons.lang3.StringUtils

You can find more about it here:

http://commons.apache.org/lang/api-3.1/org/apache/commons/lang3/StringUtils.html

And download the .jar here:

http://commons.apache.org/lang/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top