-1

so how may I check that? There are 36'000 files and on every event call I would need to check it, there could be plenty of these situations like: "nukasa" or "Nukasa" or "nUkasa", how may I detect all of these if I have one file name like: "NUKASA" or "nukasa" by event calling.

It's work with File not String. I just get String and then I need to work with File to check if in folder exists same file names just in Uppercase or Lowercase.

Luis
  • 75
  • 6

2 Answers2

4

Please refer below the snippet I want to show as an example:

File sampleFile = new File("Nukasa");
String valueToCheck = "NUKASA";
if(sampleFile.getName().equalsIgnoreCase(valueToCheck))
{
  //Logic you want to code goes here
}

Alternatively, you can use file.getName().toUpperCase().equals(valueToCheck) (if you assign upper case string to the variable valueToCheck). Same applies to toLowerCase() method also CAUTION: This approach works fine as long as the Locale is of English language. For other languages, it won't work as expected. So, equalsIgnoreCase() is the best way. Credits to the person who suggested this

Mohamed Idris
  • 442
  • 4
  • 10
  • 1
    `file.getName().toUpperCase().equals(valueToCheck)` is _not_ the same as using equalsIgnoreCase, it depends on your locale. Take `"i".toUpperCase().equals("I");` for example, it will fail if you set the language to turkish... I would reccomand to remove that part of your anwser. – mata Jan 11 '14 at 12:03
  • 1
    Hi mata, I've added some note. Many thanks for your suggestions! – Mohamed Idris Jan 11 '14 at 12:12
0

For case insensitive string comparison, use the String method str1.equalsIgnoreCase(str2).

ChopChop
  • 140
  • 8