Code Page and C#

Started by
8 comments, last by Codeka 14 years, 2 months ago
Hello everyone. I'm writing a Snake game for my Year 1 of Computer Games Development course, and it is in my interest to use a couple of special ASCII characters for art in the game. The game is supposed to be console-based. From what I understand, there's a code page mismatch between my development computer and the university computers which are supposed to run the game. The university computers seem to use IBM850. Both IBM437 and ISO-8859-1 include the characters that I'm interested in, such as ASCII 236 and 221. Most of the ASCII that I want is also included in IBM850, but the ones I mentioned do not seem to be. I've tried to enforce the code page using the following:
Console.OutputEncoding = System.Text.Encoding.GetEncoding("IBM437");
If this isn't the way to go about it, please tell. However, even with this, it has no effect on the results when I run my application on any of the university computers. It's not a security issue, as I've had it tested with a local administrator account as well. Could it be that the code pages I need simply aren't installed on the computers? If so, is there any way I can work around this? Keeping in mind that I have limited access to functionality within these computers.
Advertisement
C# strings are UTF-16 (Unicode), and Unicode probably contains the characters you're looking for. I would suggest trying that instead of screwing with codepages.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Yup, I'm pretty sure Unicode has what I want. The problem is that the Windows console (or the font it uses) doesn't seem to support it. At least not in my experience. Most of the time it prints a character that isn't related to what I want, or most of the time just a "?".

Am I doing something wrong? :(
Cursory reading suggests the console can only render characters that exist in the font it's using. That makes sense, and depending on how the university machines are set up, you may be entirely out of luck.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Darn. :/ Oh well.

I'll just go with a stock solution for this particular project. At least it's the only one of its kind, so I shouldn't have to deal with this problem again.

Thanks for the help you've provided. :D
For what it's worth, the two characters you mentioned have Unicode equivalents and work fine with the Lucida Console font (which, even if it is not the default font, is readily available):



Console.OutputEncoding = Encoding.GetEncoding(437);Console.WriteLine("236:\u221E, 221:\u258C");

Using Terminal (one of the available raster fonts) produces invalid output, which puzzles me as Wikipedia asserts that Terminal is based on code page 437. Stranger still, without explicitly setting the code page (which appears to default to 850 on my machine), it renders an 8 (a not completely ridiculous approximation for ∞) and a solid block.

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

Even if I set the code page, it displays "\u221E" as an "8" for me. The behavior is all kinds of weird. :/
Quote:Original post by skauert
Even if I set the code page, it displays "\u221E" as an "8" for me. The behavior is all kinds of weird. :/
Don't change the codepage if you change the font to Lucinda Console.

(BTW, "8" is a 'best-fit' mapping for ∞ on Windows. My guess is someone was trying to be funny when they made the 'best-fit' tables [wink])
Is it actually possible to programmatically change the font of a C# console window? :o After some research, it doesn't seem like it. Unless you mean manually changing it in the system, which I doubt I have access to anyway. :/

And I did test it both with and without a different code page. No matter what I do, I can't seem to get it working on the university's computers. I don't think it was meant to be. Though it's such a simple and pointless little thing anyway. :)

Again, thanks for all the input.
I think you can change it via the registry, but it would require you to close and re-open the window (doing through the UI it just changes straight away and "saves" it in the registry for next time). So probably not that easy.

Anyway, I guess you could just use ASCII characters ('-' '|' etc) with a comment in the code saying that it would've looked better with extended ASCII but it wasn't working or something :)

This topic is closed to new replies.

Advertisement