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?
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.
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.
The toLowerCase() method converts a string to lower case letters. Note: The toUpperCase() method converts a string to upper case letters.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With