0

I'm trying to compare two strings, while on one of them I'm doing some bidi manipulation:

const a = "\u202B" + "hi" + "\u202C"

console.log(a === 'hi') // false
console.log(a == 'hi') // false

The output on the screen will look the same while it's actually not. Is there a way to check for equality while not taking bidi into account (so the result of the equality check above will return true)?

sir-haver
  • 3,096
  • 7
  • 41
  • 85
  • Remove bidi parts from string before comparing. There is no other way. – Justinas Feb 09 '23 at 10:03
  • The string `"\u202Bhi\u202C"` simply isn't the string `"hi"`. You'd want to strip all bidi and perhaps other "special characters" from the string before comparison…? – deceze Feb 09 '23 at 10:03
  • @deceze yes is this possible to strip all bidi? – sir-haver Feb 09 '23 at 10:04
  • also [How can i deal with bidirectional text & numbers in pure JavaScript substring method?](https://stackoverflow.com/questions/73228179/how-can-i-deal-with-bidirectional-text-numbers-in-pure-javascript-substring-me) – pilchard Feb 09 '23 at 10:08

0 Answers0