-1

I have to call some Javascript functions from my Java code and some strings as parameter. The string may contain new line and double/single quote. So I want to escape the new line and double quote using java so that it can be passed smoothly to JS method? How to do the same?

Alan Moore
  • 71,299
  • 12
  • 93
  • 154
dev_android
  • 8,348
  • 22
  • 88
  • 145

2 Answers2

0

Use this: st.replaceAll("\\s+","") - removes all whitespaces and non visible characters such as tab, \n and for removing single quotes use str.replace("'", "") and so on for similar things.

Brane
  • 3,041
  • 2
  • 35
  • 52
0

I tried Apache common lib. StringEscapeUtils.escapeJavaScript(String) using org.apache.commons.lang.StringEscapeUtils

dev_android
  • 8,348
  • 22
  • 88
  • 145