ASCII charcters from 0x21 to 0xff

S

Scott Starker

Hi all.

What I want to do is create a control array using labels (I already figure
out how to create a control array) with 1 label equal to the ASCII font
character it displays. What I have found out is every font character from
0x79 to 0xA0 that get converted to a string contains the 4 sided block
character. I want to be all separate characters. Using the following:
Encoding u16LE = Encoding.Unicode;

char[] DisplayCount = new char[0xff-0x20];

for (int i = 0; i < 0xff - 0x20; i++)

{

DisplayCount = Convert.ToChar(i + 0x21);

}

bytes = u16LE.GetBytes(DisplayCount);



I have tried:
aLabel.Text = Convert.ToString(Convert.ToChar(bytes[2 * (this.Count - 1)]));

aLabel.Text = String.Format("{0}",
Convert.ToChar((bytes[2*(this.Count-1)])));

aLabel.Text = (Convert.ToChar((bytes[2*(this.Count-1)])).ToString();

aLabel.Text = Convert.ToChar(this.Count + 0x20).ToString();



So, I think is it is related is the string. Could somebody offer a
suggestion?

Scott
 
M

Michael C

Scott Starker said:
So, I think is it is related is the string. Could somebody offer a
suggestion?

The font you are using does not have these character. You need to find a
font that does.

Michael
 
M

Michael C

Scott Starker said:
No. I don't believe so. All the fonts are this way include the ANSI fonts.

Some fonts at least will have some of these chrs.

Michael
 
M

Michael C

Scott Starker said:
No. I don't believe so. All the fonts are this way include the ANSI fonts.

BTW, I think your code should look something like this:

string s = string.empty;
for i = whatever to whatever
{
s+= Convert.ToChar(i)
}
label1.text = s;

Michael
 
C

Chris Priede

Hi,

Scott said:
I have found out is every font character from 0x79 to 0xA0 that get
converted to a string contains the 4 sided block character. I want to be
all separate characters.
Using the following: Encoding u16LE = Encoding.Unicode;

What you have found is true. Unicode characters in that range are defined
as control characters (similar to characters under 0x20) and have no visual
representation. You may wish to consult:

http://www.google.com/search?hl=en&q=unicode+character+map

If you were expecting something else, you were expecting results from
different encoding, such as ISO-8859-1 -- but probably not ASCII as
mentioned in the subject of your post, for that would be undefined above
0x7F entirely.
 
J

Jon Skeet [C# MVP]

Scott Starker said:
What I want to do is create a control array using labels (I already figure
out how to create a control array) with 1 label equal to the ASCII font
character it displays. What I have found out is every font character from
0x79 to 0xA0 that get converted to a string contains the 4 sided block
character.

You need to understand that those characters *aren't* in ASCII. I
suspect you want the characters in the default encoding instead
(Encoding.Default). Try converting byte 0x79 into a character using the
default encoding, and you may well find it gives what you expect. Just
don't think that that's ASCII, or that it'll give the same result on
all computers.
 
S

Scott Starker

Having to delve into this, I know that ASCII is seven-bit code (0x0 -
0x7f).

In addition to the ASCII characters, ISO Latin 1 (ISO 8859-1) contains
various accented characters and other letters needed for writing
languages of Western Europe, and some special characters. These
characters occupy code positions 0xa0 - 0xff.

But there are 21 characters in the middle that are not displayed. In the
Windows character set (Windows code page 1252), some positions in the
range 0x80 - 0x9f are assigned to printable characters, such as "smart
quotes", em dash, en dash, and trademark symbol. I need to know how to
get these characters assigned to the labels. I wrote a program in VB6
which does this.

Hmmm... what about changing the code page... I'll give it a try...
 
J

Jon Skeet [C# MVP]

Scott Starker said:
Having to delve into this, I know that ASCII is seven-bit code (0x0 -
0x7f).

In addition to the ASCII characters, ISO Latin 1 (ISO 8859-1) contains
various accented characters and other letters needed for writing
languages of Western Europe, and some special characters. These
characters occupy code positions 0xa0 - 0xff.

But there are 21 characters in the middle that are not displayed. In the
Windows character set (Windows code page 1252), some positions in the
range 0x80 - 0x9f are assigned to printable characters, such as "smart
quotes", em dash, en dash, and trademark symbol. I need to know how to
get these characters assigned to the labels. I wrote a program in VB6
which does this.

Hmmm... what about changing the code page... I'll give it a try...

Changing the code page changes potentially a *lot* of the character
set. It's not that "the Windows character set" is Windows CP 1252 -
that's just the default for the US and Western Europe, I believe. Try
installing in Eastern Europe and I suspect you'd get a different
default...
 
S

Scott Starker

In running the program, under Encoding.Default I get:
BodyName: "iso-8859-1"
CodePage: 1252
HeaderName: "Windows-1252"
WebName: "Windows-1252"
WindowsCodePage: 1252
How do you make "Windows-1252" or 1252 win over "iso-8859-1"? They're not
the same.
 
J

Jon Skeet [C# MVP]

Scott Starker said:
In running the program, under Encoding.Default I get:
BodyName: "iso-8859-1"
CodePage: 1252
HeaderName: "Windows-1252"
WebName: "Windows-1252"
WindowsCodePage: 1252
How do you make "Windows-1252" or 1252 win over "iso-8859-1"? They're not
the same.

Running which program? Anyway, I suspect the reason it uses iso-8859-1
as the BodyName is that it's the closest MIME-compatible encoding to
Windows 1252.

However, if you want to use ISO-8859-1 at any point, just use
Encoding.GetEncoding(28591).
 
S

Scott Starker

Running which program?

With Microsoft Visual C# 2005 running in "Start Debbuging" with my C# code
:) I had the debbuger go down to this.AddNewLabel(font)
Encoding Default = Encoding.Default;
char[] DisplayCount = new char[0xff-0x20];
for (int i = 0; i < 0xff - 0x20; i++)
{
DisplayCount = Convert.ToChar(i + 0x21);
}
bytes = Default.GetBytes(DisplayCount);
this.AddNewLabel(fonts);
And in "Locals" I click on "Default" to show this list. (I know that you
knew that :) )

What I WANT is Windows-1252 and not "iso-8859-1". If C# wont allow
Windows-1252 to be used I'll have to stick when VB6 for this program.

Scott
 
J

Jon Skeet [C# MVP]

Scott said:
What I WANT is Windows-1252 and not "iso-8859-1". If C# wont allow
Windows-1252 to be used I'll have to stick when VB6 for this program.

You can use 1252 whenever you like - just use
Encoding.GetEncoding(1252) and then use that to convert between text
and binary.

Jon
 
S

Scott Starker

It is not the string but the char. In order to put character into Label I
have to use char to go to string. But "the.NET Framework uses the Char
structure to represent Unicode characters". Ugh! And there is no way that I
can get 0x80 - 0xa0 characters to display on the labels with unicode! Well,
back to VB6...
 
J

Jon Skeet [C# MVP]

Scott Starker said:
It is not the string but the char. In order to put character into Label I
have to use char to go to string. But "the.NET Framework uses the Char
structure to represent Unicode characters". Ugh! And there is no way that I
can get 0x80 - 0xa0 characters to display on the labels with unicode! Well,
back to VB6...

The 0x80 - 0xa0 you're talking about aren't characters though - they're
bytes which are the result of encoding characters. So to get characters
from those bytes, just use Encoding.GetString (bytes). As you want a
single byte to single character map, you might as well use:

byte[] bytes = new byte[256];
for (int i=0; i < bytes.Length; i++)
{
bytes = (byte)i;
}
char[] chars=Encoding.GetEncoding(1252).GetString(bytes).ToCharArray();

The problem was that you were converting from byte to char without
taking any specific encoding into account - or rather, assuming UTF-16,
effectively.
 
S

Scott Starker

Jon,

AWESOME! You did it! I didn't think about using GetString(bytes)...

However, you only have half of it. The problem is that there aren't any
characters for 0x80 - 0xa0 in Unicode. And char always gives Unicode
"characters". But since GetString(bytes) (under Encoding.GetEncoding(1252))
gives Unicode fonts for fonts 0x80 - 0xa0 I (eg. 0x80 = 8362 Unicode "?")
still don't have a single byte to single character map (eg. 0x80 = 0x80
"?"). Your solution works but only half way.

I'm trying to write a program that lists a ButtonArray of custom-made-font
(256 characters) and a LabelArray Arial font (256 characters) and have the
user click on the custom-make-font that changed because they don't go with
the Arial font. Your solution works for the Arial but not with the
custom-made-fonts. So, any ideas as to how to do 0x80 - 0xa0 (eg. 0x80 =
0x80 "?")?

Scott

Jon Skeet said:
Scott Starker said:
It is not the string but the char. In order to put character into Label I
have to use char to go to string. But "the.NET Framework uses the Char
structure to represent Unicode characters". Ugh! And there is no way that
I
can get 0x80 - 0xa0 characters to display on the labels with unicode!
Well,
back to VB6...

The 0x80 - 0xa0 you're talking about aren't characters though - they're
bytes which are the result of encoding characters. So to get characters
from those bytes, just use Encoding.GetString (bytes). As you want a
single byte to single character map, you might as well use:

byte[] bytes = new byte[256];
for (int i=0; i < bytes.Length; i++)
{
bytes = (byte)i;
}
char[] chars=Encoding.GetEncoding(1252).GetString(bytes).ToCharArray();

The problem was that you were converting from byte to char without
taking any specific encoding into account - or rather, assuming UTF-16,
effectively.
 
J

Jon Skeet [C# MVP]

Scott Starker said:
AWESOME! You did it! I didn't think about using GetString(bytes)...

However, you only have half of it. The problem is that there aren't any
characters for 0x80 - 0xa0 in Unicode.

Well, those characters do exist, but they're non-printable.
And char always gives Unicode
"characters". But since GetString(bytes) (under Encoding.GetEncoding(1252))
gives Unicode fonts for fonts 0x80 - 0xa0 I (eg. 0x80 = 8362 Unicode "?")
still don't have a single byte to single character map (eg. 0x80 = 0x80
"?"). Your solution works but only half way.

The unicode character is independent of the font, but you need to use a
font which can display the unicode character appropriately.
I'm trying to write a program that lists a ButtonArray of custom-made-font
(256 characters) and a LabelArray Arial font (256 characters) and have the
user click on the custom-make-font that changed because they don't go with
the Arial font. Your solution works for the Arial but not with the
custom-made-fonts. So, any ideas as to how to do 0x80 - 0xa0 (eg. 0x80 =
0x80 "?")?

If the font is displaying Unicode 0x80 as if it were Unicode 8362, then
you just need to use the implicit conversion from byte to char (or
explicitly convert from int to char with a cast expression). I'd say
the font is broken, however.
 
S

Scott Starker

Jon,

Forget my message before this one! When the Unicode font is "made" from the
custom-made-font (it has only 256 characters) the 0x80 - 0xa0 are exactly
they are in 0x80 - 0xa0. Thus, for instance, 0x80 is "supposed" to be 8362
Unicode (that's what the "chars" says) but it displays 0x80! I didn't even
let the characters be display because the "chars" says that it was wrong but
one time I did. It must be because the font has 256 characters. Very
interesting...

Thanks again!

Scott

Scott Starker said:
Jon,

AWESOME! You did it! I didn't think about using GetString(bytes)...

However, you only have half of it. The problem is that there aren't any
characters for 0x80 - 0xa0 in Unicode. And char always gives Unicode
"characters". But since GetString(bytes) (under
Encoding.GetEncoding(1252)) gives Unicode fonts for fonts 0x80 - 0xa0 I
(eg. 0x80 = 8362 Unicode "?") still don't have a single byte to single
character map (eg. 0x80 = 0x80 "?"). Your solution works but only half
way.

I'm trying to write a program that lists a ButtonArray of custom-made-font
(256 characters) and a LabelArray Arial font (256 characters) and have the
user click on the custom-make-font that changed because they don't go with
the Arial font. Your solution works for the Arial but not with the
custom-made-fonts. So, any ideas as to how to do 0x80 - 0xa0 (eg. 0x80 =
0x80 "?")?

Scott

Jon Skeet said:
Scott Starker said:
It is not the string but the char. In order to put character into Label
I
have to use char to go to string. But "the.NET Framework uses the Char
structure to represent Unicode characters". Ugh! And there is no way
that I
can get 0x80 - 0xa0 characters to display on the labels with unicode!
Well,
back to VB6...

The 0x80 - 0xa0 you're talking about aren't characters though - they're
bytes which are the result of encoding characters. So to get characters
from those bytes, just use Encoding.GetString (bytes). As you want a
single byte to single character map, you might as well use:

byte[] bytes = new byte[256];
for (int i=0; i < bytes.Length; i++)
{
bytes = (byte)i;
}
char[] chars=Encoding.GetEncoding(1252).GetString(bytes).ToCharArray();

The problem was that you were converting from byte to char without
taking any specific encoding into account - or rather, assuming UTF-16,
effectively.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top