Add quotes around each word

前端 未结 2 932
天涯浪人
天涯浪人 2021-02-10 01:09

I want to transform in Java:

dd fdas dd fdas fads f das fdasf + - || dasf
into:
\"dd\" \"fdas\" \"dd\" \"fdas\" \"fads\" \"f\" \"das\" \"fdasf\" + - || \"dasf\

相关标签:
2条回答
  • 2021-02-10 01:37

    replaceAll can do this:

    String result = input.replaceAll("(\w+)", "\"$1\"");
    
    0 讨论(0)
  • 2021-02-10 01:46

    It's fairly simple. Use preg_replace and sorround all text captures with quotes.

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

    You will have to find the replacement of preg_replace for java :)

    0 讨论(0)
提交回复
热议问题