2

I can't understand why indexOf is not working. character "İ" in İstanbul is UTF-8 character but after converting this string to lowercase it looks ok?!

var t = "İstanbul";
var q = "ist";
filterCandidate = t.toLowerCase(); //"istanbul"

var valueToMatch = filterCandidate.trim().substring(0, q.length); //"is"

console.log("filterCandidate: " + filterCandidate);
console.log("valueToMatch: " + valueToMatch);
showElement = false;
if (q.indexOf(valueToMatch) > -1) {
  showElement = true;
  
}
console.log("showElement: " + showElement);

1
  • 1
    i and lowercase İ are two different characters. Commented Feb 6, 2018 at 7:53

3 Answers 3

5

Lowercase of İstanbul is i̇stanbul not istanbul (Note: difference between & i).

You told in comment:

In turkish "I" is "İ" and "i" is "i". This function only works only when I use "İ". Customers may use lowercsae "i" where it is not working

Solution: Use t.toLocaleLowerCase('tr-TR') instead of t.toLowerCase().

"İstanbul".toLowerCase()                // i̇stanbul 
"İstanbul".toLocaleLowerCase('tr-TR')   // istanbul

var t = "İstanbul";
var q = "ist";
filterCandidate = t.toLocaleLowerCase('tr-TR'); //"istanbul"
var valueToMatch = filterCandidate.trim().substring(0, q.length);

console.log("filterCandidate: " + filterCandidate);
console.log("valueToMatch: " + valueToMatch);
showElement = false;
if (q.indexOf(valueToMatch) > -1) {
  showElement = true;
  
}
console.log("showElement: " + showElement);

Sign up to request clarification or add additional context in comments.

4 Comments

I am building Turkish website, I can't change "İstanbul" to "Istanbul", I need solution for "İstanbul"
In turkish "I" is "İ" and "i" is "i". This function only works only when I use "İ". Customers may use lowercsae "i" where it is not working
ok, use .toLocaleLowerCase('tr-TR') instead of .toLowerCase()
I appreciate this. It was causing problem when filtering in jsgrid table.
0

Take care my friend the letter "İ" is not the same the letter "I" some the lowercase of the letter "İ" will never be the same as the letter "I" and the evidence is ....

 var t = "İstanbul";
 var q = "ist";
 filterCandidate = t.toLowerCase();
 filterCandidate.toUpperCase(); //this will return "İSTANBUL" again

Another evidence is try :-

filterCandidate.length // This will return 9 not 8 also the word have only 8 letters.

and another try this :-

filterCandidate[1] // It will return strange letter "̇"

Comments

0

better create a substitute object for holding special character data.

var sub = {"İstanbul":"Istanbul"}

var data = "İstanbul";
var t = sub[data]

Rest of the code will work accordingly

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.