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

108
Views
Is there a way to know the number of characters in a string?

This question concerns unicode characters that are more than one utf-16 character

string.length returns the number of unicode 16 chars in the string. But what about the case of characters that are more than 1 unicode 16 character? Is it possible to get the actual number of characters as well as "true" values from string.charAt of the actual character, and not the utf-16 pieces?

var test = "🀄";
console.log(test.length)
var regex = /[\u{1F000}-\u{1F0FF}]/g;
var regex2 = /🀄/g
console.log('test: ' + regex.test(test));
console.log('test2: ' + regex2.test(test));

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Another option is to use RegExp with the unicode flag.

var test = "🀄";
var length = test.match(/./ug).length;
console.log(length);

Please note that this and the answer using the spread operator can break under certain circumstances.

var test = "Z͑ͫ̓ͪ̂ͫ̽͏̴̙̤̞͉͚̯̞̠͍A̴̵̜̰͔ͫ͗͢L̠ͨͧͩ͘G̴̻͈͍͔̹̑͗̎̅͛́Ǫ̵̹̻̝̳͂̌̌͘";
var length = test.match(/./ug).length;
console.log(length);

To get the char at a specific index you can use the following function.

var test = "🀄👼👺💩";

var charAt = charAt(test);

console.log(charAt);

function charAt(string, index) {
    if(!index)
        index = 0;

    return string.match(/./ug)[index];
}

about 4 years ago · Juan Pablo Isaza Report

0

you can use spread operator:

var test = "🀄";
var test2 = [...test];
console.log(test.length);
console.log(test2.length);

about your second question, you need to modify regexp:

var test = "🀄";
console.log(test.length)
var regex = /[\u{1F000}-\u{1F0FF}]/ug;
var regex2 = /🀄/g
console.log('test: ' + regex.test(test));
console.log('test2: ' + regex2.test(test));

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!