3 ms·
Very good article, but I am left with this question: is there any way to compare two strings representing names that is complete and correct, regardless of casi
by herodotus 7y ago
Very good article, but I am left with this question: is there any way to compare two strings representing names that is complete and correct, regardless of casing in the two original strings?
- gumby 7y agoThat is the topic of the very last part of the article -- on case folding.
- lmm 7y agoNo, not without additional information. You can't tell whether a name that says i is equivalent to one that says I without knowing more about where the names come from. And in Japanese even two identical codepoint sequences might represent different names (kanji with multiple readings).
- sametmax 7y agoThe part "Case-insensitive comparison requires case folding" says there is an algo for that, but it's up to the language to implement it. E.G: in Python 3, it's recommend to use str.casefold() instead of str.lower() for this: >>> "Straße".upper().lower() 'strasse' >>> "Straße".lower() 'straße' >>> "Straße".casefold() 'strasse' >>> Depending of the context, a little str.strip() and/or a str.split() + str.join() may also help. User usually don't want to consider blanks when entering data (e.g: an address), while it's important for machines (e.g: a password). Now like @lmm said, this only normalize the codepoints. Meaning is of course, impossible to be sure that way.
- dukoid 7y agoThe example is outdated: https://en.wikipedia.org/wiki/Capital_%E1%BA%9E https://en.wikipedia.org/wiki/Capital_%E1%BA%9E
- a1369209993 7y agoIf you mean human names, this is fundamentally impossible no matter what you do because of things like "MᶜDonald" vs "McDonald" vs "MacDonald". If you mean user or variable names, you should probably just treat them as case sensitive.