469,299 Members | 2,069 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,299 developers. It's quick & easy.

ASCII charcters from 0x21 to 0xff

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[i] = 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
Jan 10 '06 #1
17 7712
"Scott Starker" <Sc***********@sil.org> wrote in message
news:eU****************@TK2MSFTNGP10.phx.gbl...
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
Jan 10 '06 #2
No. I don't believe so. All the fonts are this way include the ANSI fonts.

"Michael C" <mc*****@NOSPAMoptushome.com.au> wrote in message
news:OG**************@TK2MSFTNGP09.phx.gbl...
"Scott Starker" <Sc***********@sil.org> wrote in message
news:eU****************@TK2MSFTNGP10.phx.gbl...
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

Jan 10 '06 #3
"Scott Starker" <Sc***********@sil.org> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
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
Jan 10 '06 #4
"Scott Starker" <Sc***********@sil.org> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
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
Jan 10 '06 #5
Hi,

Scott Starker wrote:
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...+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.
--
Chris Priede
Jan 10 '06 #6
Scott Starker <Sc***********@sil.org> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 10 '06 #7
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...

*** Sent via Developersdex http://www.developersdex.com ***
Jan 10 '06 #8
Scott Starker <sc***********@sil.org> wrote:
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...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 10 '06 #9
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.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Scott Starker <sc***********@sil.org> wrote:
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...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jan 11 '06 #10
Scott Starker <Sc***********@sil.org> wrote:
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).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 11 '06 #11
> 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[i] = 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

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Scott Starker <Sc***********@sil.org> wrote:
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).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jan 11 '06 #12
Scott Starker wrote:
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

Jan 11 '06 #13
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...

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Scott Starker wrote:
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

Jan 11 '06 #14
Scott Starker <Sc***********@sil.org> wrote:
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[i] = (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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 11 '06 #15
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 [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Scott Starker <Sc***********@sil.org> wrote:
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[i] = (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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jan 12 '06 #16
Scott Starker <Sc***********@sil.org> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 12 '06 #17
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" <Sc***********@sil.org> wrote in message
news:O1*************@TK2MSFTNGP14.phx.gbl...
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 [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Scott Starker <Sc***********@sil.org> wrote:
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[i] = (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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Jan 13 '06 #18

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Peter Wilkinson | last post: by
5 posts views Thread by Sam Smith | last post: by
5 posts views Thread by mail2atulmehta | last post: by
12 posts views Thread by chunhui_true | last post: by
1 post views Thread by Scott Duckworth | last post: by
5 posts views Thread by fidtz | last post: by
23 posts views Thread by Jorge Peixoto | last post: by
44 posts views Thread by Pilcrow | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.