I am working on decoding text. I am trying to find the character code for the —
character, not to be mistaken for -
, in ASCII. I have tried unsuccessfully. Does anybody know how to convert it?
7 Answers
Quotation from wiki (Em dash)
When an actual em dash is unavailable—as in the ASCII character set—a double ("--") or triple hyphen-minus ("---") is used. In Unicode, the em dash is U+2014 (decimal 8212).
Em dash character is not a part of ASCII character set.
-
So when I do:
char check = s.charAt(0)
, when s =—
, what I will get? Do you say that if I will doint check = s.charAt(0)
, I will get 8212?– Adam ShApr 27, 2012 at 20:57 -
5@AdamSh It depends on what you are using to do the decoding. You didn't post any code, so it is hard to tell. Commonly when a decoder encounters something it can't decode it replaces it with a question mark.– vcsjonesApr 27, 2012 at 21:01
-
You should either throw an exception or start using bigger integers and return 8212.– Li0liQApr 27, 2012 at 21:31
-
JavaScript strings are Unicode (ie, they are not limited to ASCII), so if you do s.charAt(0), then you will get the em dash, which will be equal to
s = '\u2014'
May 24, 2016 at 1:02
—
is known as an Em Dash. It's character code is \u2014
. It is not an ASCII character, so you cannot decode it with the ASCII character set because it is not in the ASCII character table. You would probably want to use UTF8 instead.
-
JavaScript strings are Unicode enabled but use UCS-2, not UTF-8, internally. Either way, there is no need to know the encoding to represent it, as you can check it against the Unicode code point in the form
\u2014
as you said. May 24, 2016 at 1:04
Windows For Windows on a keyboard with a Numeric keypad:
Use Alt+0150 (en dash), Alt+0151 (em dash), or Alt+8722 (minus sign) using the numeric keypad.
This character does not exist in ASCII, but only in Unicode, usually encoded by UTF-8.
In UTF-8, characters are encoded by 2- or 3-byte sequences (or occasionally longer), where none of the two or three bytes is a valid ASCII code, where all of them are outside the ASCII range of 0 through 127.
One suspects that the foregoing only partly answers your question, but if so then this is probably because your question is, inadvertently, only partly asked. For further details, you can extend your question with more specifics.
The character —
is not part of the ASCII set.
But if you are looking to convert it to some other format (like U+hex), you can use this online tool. Put your character into the first green box and click "Convert" (above the box)
further below you'll find a number of different codes, including U+hex:
U+2014
Feel free to edit this answer if the link breaks or leave a comment so I can find a replacement.
alt-196 - while holding down the 'Alt' key, type 196 on the numeric keypad, then release the 'Alt' key
-
3@MadDot, your answer doesn't address the context of the question, which is about the character code of the character, not how to type it. (Also, the character you describe is U+2500, whereas the question is about U+2014. Tip: In a web browser, hit F12 and paste into the console
"—".codePointAt(0).toString(16)
) Mar 28, 2019 at 16:32
mdash
is represented with number 151.