Given a string that can only be a single ASCII character or an emoji char sequence. How can I tell one from another?
The idea is to separate emojis from plain text, by the spec if you are given a string of chars mixed with emojis then by doing for (..of)
you can get substrings of ASCII chars and Emojis sparately
const text = 'ascii and emojis mixed'
for (const char of text) {
// ... here, a char would be either an ASCII char or an emoji sequence string
if (seeIfAscii(char)) {
console.log('ASCII', char);
} else {
console.log('Emoji', char);
}
}
function seeIfAscii(char) {
// what comes here? <--- QUESTION!!!
}
As to why, I need to clump ASCII chars together and keep emojis one by one separate.
CodePudding user response:
You can use String.charCodeAt
to get the unicode number of the character:
> x = "abc