What's the ASCII character code for '—'?
Asked Answered
M

8

47

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?

Maronite answered 27/4, 2012 at 20:47 Comment(5)
What do you mean by 'decode this char'? What encoding is used in the source text, and what encoding should be used in the result?Unfeeling
@raina77ow: I try to find the number of this char in Ascii tableMaronite
It's not there; therefore, its code depends on what encoding is used. For example, in Latin-1 texts mdash is represented with number 151.Unfeeling
Also see #631906Repugn
This char doesn't fall in the ASCII range.Folse
B
60

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.

Biota answered 27/4, 2012 at 20:54 Comment(4)
So when I do: char check = s.charAt(0), when s = , what I will get? Do you say that if I will do int check = s.charAt(0), I will get 8212?Maronite
@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.Ravenravening
You should either throw an exception or start using bigger integers and return 8212.Biota
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'Riane
R
19

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.

Ravenravening answered 27/4, 2012 at 20:54 Comment(1)
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.Riane
T
11

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.

Tactical answered 20/5, 2020 at 13:32 Comment(0)
A
4

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.

Anuran answered 27/4, 2012 at 20:55 Comment(0)
D
3

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.

Dunfermline answered 17/5, 2018 at 1:18 Comment(0)
C
2

Alt + 0151 seems to do the trick—perhaps it doesn't work on all keyboards.

Cavanagh answered 19/6, 2020 at 14:4 Comment(0)
M
1

It's 150. You can replace Chr(150) with a normal hyphen, Chr(45).

Marotta answered 3/10, 2023 at 10:36 Comment(0)
S
-6

alt-196 - while holding down the 'Alt' key, type 196 on the numeric keypad, then release the 'Alt' key

Sakai answered 28/3, 2019 at 14:17 Comment(1)
@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))Colver

© 2022 - 2024 — McMap. All rights reserved.