Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"İ".toLowerCase() != "i"

In Turkish, there's a letter İ which is the uppercase form of i. When I convert it to lowercase, I get a weird result. For example:

var string_tr = "İ".toLowerCase();
var string_en = "i";

console.log( string_tr == string_en );  // false
console.log( string_tr.split("") );     // ["i", "̇"]
console.log( string_tr.charCodeAt(1) ); // 775
console.log( string_en.charCodeAt(0) ); // 105

"İ".toLowerCase() returns an extra character, and if I'm not mistaken, it's COMBINING DOT ABOVE (U+0307).

How do I get rid of this character?

I could just filter the string:

var string_tr = "İ".toLowerCase();

string_tr = string_tr.split("").filter(function (item) {
    if (item.charCodeAt(0) != 775) {
        return true;
    }
}).join("");

console.log(string_tr.split(""));

but am I handing this correctly? Is there a more preferable way? Furthermore, why does this extra character appear in the first place?

There's some inconsistency. For example, in Turkish, there a lowercase form of I: ı. How come the following comparison returns true

console.log( "ı".toUpperCase() == "i".toUpperCase() ) // true

while

console.log( "İ".toLowerCase() == "i" ) // false

returns false?

like image 661
akinuri Avatar asked Oct 16 '17 12:10

akinuri


People also ask

What does toLowerCase mean in JavaScript?

Description. The toLowerCase() method returns the value of the string converted to lower case. toLowerCase() does not affect the value of the string str itself.

What is the return type of toLowerCase () function?

The java string toLowerCase() method returns the string in lowercase letter. In other words, it converts all characters of the string into lower case letter.

How do I convert a string to lowercase?

The toLowerCase() method converts a string to lower case letters. Note: The toUpperCase() method converts a string to upper case letters.

How does toLowerCase work java?

Java String toLowerCase() method is used and operated over string where we want to convert all letters to lowercase in a string. There are two types of toLowerCase() method as follows: toLowerCase() toLowerCase(Locale loc): Converts all the characters into lowercase using the rules of the given Locale.


1 Answers

You’ll need a Turkish-specific case conversion, available with String#toLocaleLowerCase:

let s = "İ";

console.log(s.toLowerCase().length);
console.log(s.toLocaleLowerCase('tr-TR').length);
like image 97
Ry- Avatar answered Oct 26 '22 14:10

Ry-