I have a complex algorithm, one module is written in Python and another in JavaScript.
At some point these modules calculate string length.
The problem is when the text contains emojis, Python and JS give different results.
Example:
The JS's length is more convenient in my case. Is there a way to make Python3 calculate the emoji's length as JS does?
Here's the Python function to calculate string length that can contain emoji. It returns the same result as JS:
def jslen(string):
return int(len(string.encode(encoding='utf_16_le'))/2)
Thank you @snakecharmerb for your hint!