4

I expect Print[FromCharacterCode[{97, 0, 97}, "ASCII"]] output to look the same as Print[FromCharacterCode[{97, 97}, "ASCII"]], but instead it looks like Print[FromCharacterCode[{97, 32, 97}, "ASCII"]].

I see that the "Null space" is being handled differently; FromCharacterCode[{0}, "ASCII"] == FromCharacterCode[{32}, "ASCII"] outputs False. But why would it display anything in the first place?

Non ASCII seems to work as I expect."a"~StringJoin~"\[Null]"~StringJoin~"a" outputs without displaying a separation but still keeping a Null in the middle. BTW I had to type it in backwards to avoid \[Nu]. And it works as I expect with "UTF-8". ex: FromCharacterCode[{97, 97, 239, 142, 160, 97}, "UTF-8"].

I will be switching to UTF-8 but just curious about ASCII.

kirma
  • 19,056
  • 1
  • 51
  • 93
9Harris
  • 175
  • 6
  • FromCharacterCode[{0}, "ASCII"] == FromCharacterCode[{0}, "ASCII"] returns True for me for all versions I can try now on my Mac, from v12.2 onwards. Also, the string with character code 0 does visually look like "aa" to me, although I wouldn't expect anything from that visual presentation. What is your Mathematica version and on what platform? – kirma Feb 20 '23 at 04:43
  • 1
    Typo on that line of code. Edited to read FromCharacterCode[{0}, "ASCII"] == FromCharacterCode[{32}, "ASCII"] outputs False as expected. – 9Harris Feb 20 '23 at 05:13
  • 12.1.1.0 Microsoft Windows (64-bit) – 9Harris Feb 20 '23 at 05:14
  • This may be simply font-specific behaviour. Compare with https://mathematica.stackexchange.com/q/190000/3056 – kirma Feb 20 '23 at 05:20
  • 1
    This is also related: https://mathematica.stackexchange.com/q/123736 . Apparently Consolas, used on Windows at least on some versions of Mathematica, shows a space for the zero character, while Source Code Pro, used on Mac on recent versions, doesn't. – kirma Feb 20 '23 at 05:34
  • I get the bell with :260E but not a pixel exact match. I'm willing to chalk this up to a quirk on some user specific software. – 9Harris Feb 20 '23 at 05:38

1 Answers1

3

This is likely to be a font issue; both Consolas and Source Code Pro are used as the default code font on at least some Mathematica versions.

enter image description here

You can check your current set code font:

CurrentValue[{StyleHints, "CodeFont"}]

(* "Source Code Pro" *)

(That's on my Mac running v13.2.1.)

Only even semi-sensible reason for having different fonts on different platforms that I can come up with is that Consolas might render just a bit better on the Windows platform. No idea if that's the rationale chosen by WRI, though.

kirma
  • 19,056
  • 1
  • 51
  • 93