Quantcast
Channel: How to reverse a string that contains complicated emojis? - Stack Overflow
Browsing index pages (11 articles)

How to reverse a string that contains complicated emojis?

Input:Hello world👩‍🦰👩‍👩‍👦‍👦Desired Output:👩‍👩‍👦‍👦👩‍🦰dlrow olleHI tried several approaches but none gave me correct answer.This failed miserablly:const text = 'Hello world👩‍🦰👩‍👩‍👦‍👦';const reversed =...

View Article


Answer by TKoL for How to reverse a string that contains complicated emojis?

I just decided to do it for fun, was a good challenge. Not sure it's correct in all cases, so use at your own risk, but here it is:function run() { const text = 'Hello world👩‍🦰👩‍👩‍👦‍👦'; const newText =...

View Article


Answer by Mark Baijens for How to reverse a string that contains complicated...

I took TKoL's idea of using the \u200d character and used it to attempt to create a smaller script.Note: Not all compositions use a zero width joiner so it will be buggy with other composition...

View Article

Answer by 0stone0 for How to reverse a string that contains complicated emojis?

If you're able to, use the _.split() function provided by lodash. From version 4.0 onwards, _.split() is capable of splitting unicode emojis.Using the native .reverse().join('') to reverse the...

View Article

Answer by Neil for How to reverse a string that contains complicated emojis?

I know! I'll use RegExp. What could go wrong? (Answer left as an exercise for the reader.)const text = 'Hello world👩‍🦰👩‍👩‍👦‍👦';const reversed =...

View Article


Answer by Michael Anderson for How to reverse a string that contains...

You don't just have trouble with emoji, but also with other combining characters.These things that feel like individual letters but are actually one-or-more unicode characters are called "extended...

View Article

Answer by Arnis Juraga for How to reverse a string that contains complicated...

Alternative solution would be to use runes library, small but effective solution:https://github.com/dotcypress/runesconst runes = require('runes')// String.substring'👨‍👨‍👧‍👧a'.substring(1) =>...

View Article

Answer by yeoman for How to reverse a string that contains complicated emojis?

Reversing Unicode text is tricky for a lot of reasons.First, depending on the programming language, strings are represented in different ways, either as a list of bytes, a list of UTF-16 code units (16...

View Article


Answer by omdha0 for How to reverse a string that contains complicated emojis?

You can use:yourstring.split('').reverse().join('')It should turn your string into a list, reverse it then make it a string again.

View Article


Answer by asfaqe hussain for How to reverse a string that contains...

const text = 'Hello world👩‍🦰👩‍👩‍👦‍👦';const reversed = text.split('').reverse().join('');console.log(reversed);

View Article

Answer by noraj for How to reverse a string that contains complicated emojis?

Using Intl.Segmenter()const text = 'Hello world👩‍🦰👩‍👩‍👦‍👦';[...new Intl.Segmenter().segment(text)].map(x => x.segment).reverse().join('');// default granularity is grapheme so no need to specify...

View Article
Browsing index pages (11 articles)


Latest Images