如何将值从 excel 单元格格式化的字符串变量与普通字符串变量进行比较?

How to compare a string variable whose value is formatted from an excel cell with a normal string variable?

我想比较用户输入的字符串和我从日期格式化为字符串的另一个字符串以获得 excel 值。我有一组对象。每个对象都有日期数据。我想从用户输入的日期开始打印这些对象。但是,我为查找对象索引而编写的方法无法正常工作。我希望你能得到我。这是我的代码; `

System.out.print("Please enter a date:");
input = new Scanner(System.in);
String date1=input.next();
int index_tarih=searching(date1, myObjects);//myObjects is my array storing my data from excel.


public static int searching(String datess,sicaklik_nesne dayss[]) 
{   int number=0;

    for(int index_number=0;index_number<dayss.lenght;index_number++)
    {
       if(dayss[index_number].Gun==datess)
        {
            sayi=9;
        }
   }    

enter code here
    return sayi;
}   

`

i.Gun=new DataFormatter().formatCellValue(cell);// this code from my class retrieving excel data.

比较字符串时请使用等号而不是==

if(dayss[index_number].Gun.equals(datess)) {
    sayi=9;
}

PS:如果你想比较字符串,不管是大写还是小写,你可以在这里使用 equalsIgnoreCase() 方法而不是 equals。