#removing the first letter from a variable

10 messages · Page 1 of 1 (latest)

daring juniper
#

Is there any difference in this code for removing the first letter from the variable? In this case, emojis.

const editFileName = String.fromCodePoint(interaction.channel.name.codePointAt(0));
const fileName = interaction.channel.name.replace(editFileName, '') + '.txt';

OR

const fileName = interaction.channel.name.substring(2) + '.txt';
uncut galeBOT
#
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
  • Marked as resolved by OP
ashen kestrel
#

Even if an emoji shows as one character it may be made by 2 or more code points.
The first code removes exactly 1 code point. The second removes exactly 2 code points.
The easiest way is to have a separator between the emoji and text (😄 Hello). Here you can split by the space and shift the emoji.
Or use a regex to remove the emoji.

brave pollen
#

Regex would be easier as Emojis are part of multibytes characters but not all multibytes characters are emojis

#

basically everything that is not using the same alphabet as english + ASCII Symbols are multibytes sequences (like à; ù in french, 漢, 字 in japanese, 한글 in korean, you get the idea)

#

If i recall correctly, emojis span over a specifc range of multibyte sequences

daring juniper
mild flameBOT
#
  • For unicode emojis (twemoji): learn more
  • Custom emojis: /<?(a)?:?(\w{2,32}):(\d{17,19})>?/ learn more
lethal hinge
#

you may also find the first link here helpful