Txppin
(Txppin)
March 31, 2020, 9:13am
#1
Hi there, I am having an issue where I am trying to add the Bullet character into one of my embeds.
I am using the following code to insert in the character:
utf8.char("0x2022")
The character gets turned into this weird unicode instead of what I wanted:
â¢
I would like to know why this happens and how I would resolve it.
RoBreadd
(Agidyne)
March 31, 2020, 9:38am
#2
Which of these characters is correct?
Txppin
(Txppin)
March 31, 2020, 9:40am
#3
The correct character should be this bullet: “• ”
EDIT: use utf8.char("8226")
. It appears just using the HTML entity (in decimal notation) works.
Post before my edit:
You’re using a library named "utf8"
which likely means you’re using utf-8
encoding. 0x2022
is the “bullet” representation in a utf-16
encoding.
Try using utf8.char("0xE2")
, utf8.char("0x80")
, or utf8.char("0xA2")
1 Like
RoBreadd
(Agidyne)
March 31, 2020, 10:39am
#5
Using utf8.char("0x2022")
and utf8.char("8226")
both work the same way. Try both and see if either works.
You’re right.
utf8.char("0x2022")
didn’t work for OP so I assumed it would not work for me. Checking again and it does work…? Weird
I don’t see why 0x2022
would work in the first place-considering 0x2022
is the 16
bit-encoding representation meanwhile the library is named utf8
.
RoBreadd
(Agidyne)
March 31, 2020, 10:51am
#7
Very interesting.
Wonder why utf8.char
doesn’t accept the hex byte sequence.
Txppin
(Txppin)
March 31, 2020, 10:58am
#8
I am still having the same issue regardless of what type of sequence I give to it.
RoBreadd
(Agidyne)
March 31, 2020, 11:01am
#9
Wrap it in a print function instead, and see what happens.
Txppin
(Txppin)
March 31, 2020, 11:02am
#10
When I print the JSONEncoded result it shows the characters properly for some reason.
Txppin
(Txppin)
April 1, 2020, 7:03am
#11
I have figured out how to fix this issue and I’m going to post how to fix it here for anyone else to check out if they run into the same issue.
If you send the webhook directly:
string.gsub(JSONEncoded Data, utf8.char("0xE2") .. utf8.char("0x80") .. utf8.char("0xA2"), utf8.char("0x2022"));
If you are sending the webhook via a Proxy or website:
You use what I gave above aswell as you change the Content-Type header to: “application/json; charset=utf-8”