Question

La réponse à Java escape HTML montre StringUtils.replaceEach() qui fonctionne de manière similaire à plusieurs StringUtils.replace()s,mais en acceptant des tableaux de Strings au lieu d'avoir à faire chaque remplacement individuellement.

Par exemple:

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

... devient ...

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

Beaucoup plus propre.

Où puis-je accéder au StringUtils.replace()?

J'ai essayé d'importer ce qui suit, en vain:

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

Ils ont chacun un .replace(), bien sûr.

Était-ce utile?

La solution

Il pense que vous recherchez: org.apache.commons.lang3.StringUtils

Vous pouvez en savoir plus ici:

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

Et téléchargez le .jar ici:

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top