[英]If I write String.toLowerCase, it won't work, but I need it, how can I solve?
ArrayList listaTesti is defined as global variable ArrayList listaTesti被定义为全局变量
the cambiaValore function takes 2 Strings from a textField cambiaValore函数从textField中获取2个字符串
the find Function takes the 2 Strings from the textField, and it should replace all the occurrences of the "testoDaModificare" with "conCheParola" I've included String.toLowerCase, so, if the user insert a uppercase value, it doesn't matter. find函数从textField中获取2个字符串,并且应该将“ testoDaModificare”的所有出现替换为“ conCheParola”(我已包含String.toLowerCase),因此,如果用户插入大写值,则没关系。
if I don't write "string.toLowerCase" it work, but if the user put a uppercase value while it there isn't, the function will not work. 如果我不写“ string.toLowerCase”,它会工作,但是如果用户在没有大写值的情况下放一个大写值,则该函数将无法工作。
private void cambiaValore(String testoDaModificare, String conCheParola)
{
ArrayList <String> appoggio = cerca(testoDaModificare, conCheParola);
int i = 0;
listaTesti.removeAll(listaTesti); //Rimuovo tutti gli elementi della lista
for (String string : appoggio) //E li ri assegno utilizzando quelli modificati
{
String temp = appoggio.get(i);
listaTesti.add(temp);
i++;
}
}
private ArrayList <String> cerca(String testoDaCambiare,String conCheParola)
{
int i = 0;
ArrayList <String> appoggio = new ArrayList();
for(String testo : listaTesti)
{
if(listaTesti.get(i).toLowerCase().contains(testoDaCambiare.toLowerCase()))
{
String testo3 = listaTesti.get(i).replaceAll(testoDaCambiare.toLowerCase(), conCheParola);
appoggio.add(testo3);
i++;
}
else
{
appoggio.add(listaTesti.get(i));
i++;
}
}
return appoggio;
}
The issue is here: 问题在这里:
String testo3 = listaTesti.get(i).replaceAll(testoDaCambiare.toLowerCase(), conCheParola);
The value returned from get(i)
has not been converted to lower case. 从
get(i)
返回的值尚未转换为小写。 You need to tell replaceAll()
to ignore case. 您需要告诉
replaceAll()
忽略大小写。
String testo3 = listaTesti.get(i).replaceAll("(?i)" + testoDaCambiare, conCheParola);
The "(?i)"
tells replaceAll
to ignore case. "(?i)"
告诉replaceAll
忽略大小写。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.