【发布时间】:2016-02-03 01:58:44
【问题描述】:
我正在编写一个与自动更正相反的程序。逻辑是用户输入一个句子,当按下按钮时,应该显示用户输入的句子的语法反义词。我大致能够得到代码。我使用了匹配器逻辑。但我无法获得所需的输出。我将代码与这个问题联系起来。谁能帮帮我?
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String input = editText.getText().toString();
String store = input;
String store1 [] = store.split(" ");
String correct[] = {"is","shall","this","can","will"};
String wrong [] = {"was","should","that","could","would"};
String output = "";
for (int i=0;i<store1.length;i++) {
for(int j=0;j<correct.length;j++){
if(store1[i].matches(correct[j])) {
output = input.replace(store1[i], wrong[j]);
//store1[i] = wrong[j];
}
else
{
input.replace(store1[i], store1[i]);
//store1[i] = store1[i];
}
}
mTextView.setText(output);
}
}});
【问题讨论】:
-
尝试使用
equalsIgnoreCase而不是matches。因为matches是正则表达式模式
标签: java android matcher autocorrect