Char Unicode value and converting to byte

G

Guest

Hi,

I'm writing a C# win application program, and i need to transfer my hebrew
letters from unicode to ascii, now if i use the ascii encoding it writes me
??? instead of the hebrew letter i've entered. I know what the Ascii value of
each letter, so i understood that i can transfer my string to BYTE and enter
the ascii value by myself. if someone has a better idea, i'll be happy to
hear about it.
how can i know the Unicode value of a charter while the program running? i
want to make subtraction between the unicode value to the difference in Ascii
so i'll always get the ASCII value.

one more thing, if someone can give me an example how can i convert my char
value to byte.
thanks,
Gidi.
 
N

Nicholas Paldino [.NET/C# MVP]

Gidi,

This sounds more like translation than encoding. As you have seen,
there isn't an encoding that will translate a Hebrew character into an Ascii
equivalent.

Since you know the character codes of the Hebrew characters you want to
translate, why not do this?

Assume that the Hebrew characters take up unicode characters 600-699
(this is a guess).

What you would do is create an array of 100 elements. If every unicode
mapping maps to a single character, then you can use a char (you should use
a char if you are going to subsequently string together words with these
character) as the array type. If the characters map to multi-character
strings, then the array should be strings.

As you are cycling through your unicode characters, subtract the value
of the low end of the range (in this case, 600). This is the element in the
array to get the equivalent character/string of, and you can append it to
your return string.

You could also place this in a class that derives from Encoding and then
it would help you in a great number of situations.

Hope this helps.
 
J

Jon Skeet [C# MVP]

Gidi said:
I'm writing a C# win application program, and i need to transfer my hebrew
letters from unicode to ascii, now if i use the ascii encoding it writes me
??? instead of the hebrew letter i've entered. I know what the Ascii value of
each letter, so i understood that i can transfer my string to BYTE and enter
the ascii value by myself. if someone has a better idea, i'll be happy to
hear about it.

I think you may be under a misapprehension about ASCII. In particular,
it doesn't contain any Hebrew characters.

See http://www.pobox.com/~skeet/csharp/unicode.html

Now, did you actually mean that you know some ASCII translation for
each Hebrew letter?

Jon
 

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