Add quotes around each word

I want to convert to Java:

dd fdas dd fdas fads f das fdasf + - || dasf
in:
"dd" "fdas" "dd" "fdas" "fads" "f" "das" "fdasf" + - || "Dasf"

Basically I want to add quotes around the words. \ w * → "\ w * \"

+4
source share
2 answers

replaceAll can do this:

 String result = input.replaceAll("(\w+)", "\"$1\""); 
+7
source

It is pretty simple. Use preg_replace and orient all captures of text with quotes.

 preg_replace("/([a-z0-9]+)/i", '"$1"', $string); 

You will need to find the preg_replace replacement for java :)

0
source

All Articles