-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
  • 73,866
  • 12
  • 100
  • 156
dev_android
  • 8,698
  • 22
  • 91
  • 148

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,257
  • 2
  • 42
  • 53
0

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

dev_android
  • 8,698
  • 22
  • 91
  • 148