⚠️ 이슈
✅ 해결
- In detail, this function first uses TextEncoder to convert content into a byte array with utf-8 encoding, then loops through this array, if it finds a byte whose first five bits are 11110 (i.e. 0xF0), it means this is an emoji start, then it replaces this byte and the next three bytes with 0x30 (i.e. number 0). Finally, it uses TextDecoder to convert the modified byte array back to a string, and uses replaceAll method to remove extra 0s.
function removeEmoji (content) {
let conByte = new TextEncoder("utf-8").encode(content);
for (var i = 0; i < conByte.length; i++) {
if ((conByte[i] & 0xF8) == 0xF0) {
for (var j = 0; j < 4; j++) {
conByte[i+j]=0x30;
}
i += 3;
}
}
content = new TextDecoder("utf-8").decode(conByte);
return content.replaceAll("0000", "");
}
Ref
'Language > JavaScript' 카테고리의 다른 글
[JS] 문자열 자르기 (0) | 2023.11.08 |
---|---|
자바스크립트 람다식(화살표 함수) (0) | 2023.04.19 |
Broadcast Channel API (0) | 2023.04.19 |
formData 키값 출력 (0) | 2023.04.12 |
for / for in / for of (2) | 2022.12.15 |