Re:The complete guide to working with strings in modern Java...
by rav on Tuesday April 13, 2021 @10:59AM
(#26793081)
localeCompare() returns 0 if the strings are equal and -1/+1 if they're different. Since this section is about comparing two strings that only differ in case and accents, I would expect to see a method I could use that would consider the strings to be equal. Instead, this example just shows two ways to compare strings (=== and localeCompare) that both consider the strings to be different.
[ Parent
| on HN ]
Re:The complete guide to working with strings in modern Java...
by davethedevguy on Tuesday April 13, 2021 @11:06AM
(#26793183)
Thank you, you're right that's a mistake.
This example was supposed to use: {sensitivity: 'base'}
I've corrected it.
Re:The complete guide to working with strings in modern Java...
by mormegil on Tuesday April 13, 2021 @01:40PM
(#26796087)
Not really. Case (in) sensitivity and accent (in)sensitivity are two orthogonal things. If you want to compare two strings, ignoring case differences, converting both to lowercase (or uppercase) is completely fine in Javascript (it might be problematic in other languages because of Turkish dotted and dotless i, but in JS, the obvious first-choice toLowerCase() is locale-ignorant, you would need to use toLocaleLowerCase() to be bitten by the problem and why would do that?). Obviously, the method considers "Á" and "a" to be different, but why wouldn't it? Those characters differ in accents, not only in case.
Re:The complete guide to working with strings in modern Java...
by mixmastamyk on Tuesday April 13, 2021 @02:26PM
(#26796799)
I came to write this. Why are accents being disregarded under the case-insensitive comparison section?
The proper solution is typically "case fold", however I only know it from Python, not sure if Javascript supports it natively.
Re:The complete guide to working with strings in modern Java...
by davethedevguy on Tuesday April 13, 2021 @04:26PM
(#26798776)
Thanks for this.
I've split 'Handling diacritics' in to a separate section to 'Case sensitivity'.
Re:The complete guide to working with strings in modern Java...
by davethedevguy on Tuesday April 13, 2021 @01:44PM
(#26796164)
> Case (in) sensitivity and accent (in)sensitivity are two orthogonal things
Is that definitely true?
As I understand it (and I admit I'm no expert), it's common to omit accents in some languages when changing case.