import std.stdio;
void main()
{
// expect 14 but 16
writeln("len of –2_147_483_648: ", "–2_147_483_648".length);
}
Comment #1 by ag0aep6g — 2016-09-27T20:13:15Z
You're using an en dash for the minus sign there. That's code point U+2013, which is encoded in UTF-8 with three code units / bytes. .length gives the length in code units, so 16 is correct.
Closing as invalid. Please reopen if I missed something.
Comment #2 by apz28 — 2016-09-28T00:09:32Z
The const is not consistent. run below codes
import std.stdio;
void main()
{
writeln('-', " minus#: ", cast(int) '-');
writeln("-", " len: ", "-".length);
writeln("-1", " len: ", "-1".length);
writeln("-12345", " len: ", "-12345".length);
writeln("–2_147_483_648", " len: ", "–2_147_483_648".length);
}
Comment #3 by schveiguy — 2016-09-28T02:31:46Z
(In reply to apham from comment #2)
> writeln('-', " minus#: ", cast(int) '-');
> writeln("-", " len: ", "-".length);
> writeln("-1", " len: ", "-1".length);
> writeln("-12345", " len: ", "-12345".length);
All of the above are using normal ascii dash character (byte 0x2d).
> writeln("–2_147_483_648", " len: ", "–2_147_483_648".length);
This uses different character, it even appears different on my display (sequence 0xe2 0x80 0x93). Try this instead:
writeln("-2_147_483_648", " len: ", "-2_147_483_648".length);