问题
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