Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
JavaScript vs Python emoji length

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:

  • '๐Ÿ‘€' Python len: 1 ; JS len: 2
  • '๐Ÿ‘๐Ÿพ' Python len: 2 ; JS len: 4

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?

about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

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!

about 4 years ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!