javascriptunicodesymbolsemojicodepoint

How can I add '#' symbol/emoji in a string such that it doesn't splits the string when `split('#')` method is called on it?


Is there a way in JavaScript to display a symbol similar to '#' in a string such that "Enter #time to check time".split('#') doesn't break it into pieces?

It should return a complete string instead of ['Enter ','time to check time'].

I tried using this '#️⃣' symbol in place of '#' but it still somehow gets detected. On further debugging I found out that this emoji is composed of 2 code points out of which 1st one translates to unicode \u0023 which is similar to that of the '#' symbol. And hence it splits the string.

This might seem like a stupid issue but the underlying use case is very interesting but unfortunately I could not share here due to confidential reasons. So, any kind of help is highly appreciated.

Thanks!


Solution

  • The solution here was to switch to full-width hash symbol which has a different unicode U+FF03 whereas half-width hash symbol (which is the same as the hash symbol on the keyboard) has a unicode U+0023