0

I am comparing some Vietnamese names in Javascript. However if I copy a Vietnamese name such as "Sở giao dịch" and paste to compare with the other (using web UI) I am able to compare.

But If I type directly Vietnamese name as above then cannot compare.

I think this is because when copying the text string and comparing then the same unicode character is being compared, but when typing then other unicode character is presented.

So comparing "Sở" and "Sở" should give 0, but its not because one is copied and other is typed. But if both are copied then no problem in comparing.

So, how to compare two unicode strings that looks alike but in fact different unicode?

Btw, this question answers it but using C#, I am using javascript.

Ahmad Hijazi
  • 635
  • 2
  • 9
  • 27
  • 2
    There is a normalize function in JavaScript: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize Please post a source code (mcve) that reproduces the issue you face. – NineBerry Jul 09 '18 at 12:37
  • Just to add to @NineBerry’s answer, a simple accented character like ‘é’ can be written as a single combined character or the base character plus an accent. The principle is the same for characters like ‘ở’: they can be typed in different ways. In JavaScript, you would `normalize` both the strings and compare the results so that it doesn’t matter how they were typed. – Aankhen Jul 09 '18 at 12:50
  • Thanks, it worked :) – Ahmad Hijazi Jul 10 '18 at 11:31

0 Answers0