4
$\begingroup$

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.

$\endgroup$
6
  • $\begingroup$ 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? $\endgroup$
    – kirma
    Feb 20, 2023 at 4:43
  • 1
    $\begingroup$ Typo on that line of code. Edited to read FromCharacterCode[{0}, "ASCII"] == FromCharacterCode[{32}, "ASCII"] outputs False as expected. $\endgroup$
    – 9Harris
    Feb 20, 2023 at 5:13
  • $\begingroup$ 12.1.1.0 Microsoft Windows (64-bit) $\endgroup$
    – 9Harris
    Feb 20, 2023 at 5:14
  • $\begingroup$ This may be simply font-specific behaviour. Compare with mathematica.stackexchange.com/q/190000/3056 $\endgroup$
    – kirma
    Feb 20, 2023 at 5:20
  • 1
    $\begingroup$ This is also related: 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. $\endgroup$
    – kirma
    Feb 20, 2023 at 5:34

1 Answer 1

3
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.