简体   繁体   English

如果我编写String.toLowerCase,它将无法正常工作,但是我需要它,如何解决?

[英]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.

相关问题 String.toLowerCase中的StackOverflowError - StackOverflowError in String.toLowerCase 为什么在使用 StringBuffer 后我不能使用 toLowerCase()? - How come I can't use toLowerCase() after using a StringBuffer? 如何解决Java错误:&#39;对于ArrayList类型,toLowerCase()方法未定义 <String> ” - How do I solve the Java error:'The Method toLowerCase() is undefined for the type ArrayList<String>" 为什么 String.toLowerCase() 返回的 String 没有被实习? - Why the String returned by String.toLowerCase() is not interned? 在小写字符串上执行string.tolowercase的性能 - performance of string.tolowercase on a lower case string String.toLowerCase()的用途是否具有默认语言环境? - Purpose of String.toLowerCase() with default locale? 如何修复 FindBugs 的警告“使用非本地化 String.toUpperCase() 或 String.toLowerCase()”? - How to fix FindBugs' warning "Use of non-localized String.toUpperCase() or String.toLowerCase()"? Android:如何从xml获取字符串并将其设置为LowerCase()? - Android: How do I get a string from xml and set it toLowerCase()? 我该如何解决这个 String 和 int 问题? - How can I solve this String and int problem? Lucene 如何在 StandardAnalyzer 中关闭“toLowerCase”? - Lucene how can i turn off “toLowerCase” in StandardAnalyzer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM