Java / Replace all Quotation mark

被刻印的时光 ゝ 提交于 2021-02-05 06:48:27

问题


I to replace all Quotation mark in sentence to some word.

Input: hello (and "How" are you"?")

Output: hello (and WORD are youWORD)

I try this is Java: mySentence.replaceAll("[\"].*[\"]", "WORD");

But nothing happens. How I can resolve it?


回答1:


You can use:

String replaced = mySentence.replaceAll("\".*?\"", "WORD");

Or better:

String replaced = mySentence.replaceAll("\"[^\"]*\"", "WORD");
//=> hello (and WORD are youWORD)



回答2:


you could easilly do this by converting a string in a character array.

string s= "and "?" how are you "?" "

char[] arr= s.toCharArray();

for(int i=0; i>arr.length; arr++)
{
    if(arr[i].isLetter() == false)
    {
    arr[i]= ' ';
    }
}


来源:https://stackoverflow.com/questions/21812170/java-replace-all-quotation-mark

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!