Sign in to follow this  
skauert

Code Page and C#

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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? :(

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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])

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this