Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C# String With Cyrillic Digits To Byte Array

Posted on 2010-08-27
18
Medium Priority
?
4,172 Views
Last Modified: 2013-12-17
OK guys, I have a string and it contains cyrillic  characters and digits and latin characters. And I want to convert this string to a byte array, converting it to unicode following this table.
http://www.ibm.com/developerworks/linux/library/l-u-cyr/table4.jpg
For example if I have a cyrrilic "A" the byte value should be 0xC0.
Don't tell me to use System.Text.UTF8Encoding.UTF8.GetBytes(string str) as it returns ... stupid stings :).
0
Comment
Question by:IncognitoMan
  • 9
  • 8
18 Comments
 
LVL 2

Expert Comment

by:SkydiverFL
ID: 33545208
Won't ToCharArray() return the character array?  If so, can you not just convert the individual characters to the equiv bytes?
0
 

Author Comment

by:IncognitoMan
ID: 33545242
OK Ill try converting it to byte array and then convert it to byte aquvalents. Then I'll tell you the result. :)
0
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 33545310
Try this
UnicodeEncoding unicode = new UnicodeEncoding();
Byte[] encodedBytes = unicode.GetBytes(unicodeString);
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:IncognitoMan
ID: 33545316
Nope, the byte array returns stupid things. For example it returns values like 1040 for "¿". Maybe It's UTF-16. But how do I make the string UTF-8?
0
 

Author Comment

by:IncognitoMan
ID: 33545328
OK SriVaddadi I'll try it.
By the way the character in the post above was cyrillic "A".
0
 

Author Comment

by:IncognitoMan
ID: 33545388
This retirns to bytes for an "A" 0x16 and 0x04. Any other ideas :).
0
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 33545423
How about
ASCIIEncoding ascii = new ASCIIEncoding();
Byte[] encodedBytes = unicode.GetBytes(unicodeString);
0
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 33545490
This should work

int pageCode = 1251
Encoding encoding = Encoding.GetEncoding(pageCode);
Byte[] encodedBytes = encoding.GetBytes(unicodeString)
0
 

Author Comment

by:IncognitoMan
ID: 33545521
It again returns two bytes 208 and 144. Maybe I'll try with switch case statement :), but thats not a solution.
0
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 33545582
int pageCode = 1251
Encoding encoding = Encoding.GetEncoding(pageCode);
Byte[] encodedBytes = encoding.GetBytes(unicodeString)

This should work if it is not working then the page code mentioned at the url you posted is incorrect
0
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 33545683
Did you try it?
0
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 33545723
Encoding en = Encoding.GetEncoding(1251);
            MessageBox.Show(en.EncodingName);

This give the Encoding name as cyrillic correctly. If this is not working for you then issue might be something else
0
 

Author Comment

by:IncognitoMan
ID: 33548448
I've searched all over the net and tried all of the above, as it was in other sites. Nothing worked for me. I guess I'll be writing a switch case statement with over a hundred cases. :)
0
 
LVL 16

Accepted Solution

by:
SriVaddadi earned 2000 total points
ID: 33548870
You do not need a switch statement. you need the correct windows code page. 1251 is the windows code page for Cyrillic. If tht is not what you are looking for then the language might be different with different page code. once you get the page code the code snippet in my last post should work
0
 

Author Comment

by:IncognitoMan
ID: 33549810
It works as wire and electric current with switch case statement, but it's 350 lines.
0
 

Author Closing Comment

by:IncognitoMan
ID: 33549812
Just because you searched all over the net for me, I will give you point ;).
0
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 33549814
So you could resolve the issue with switch satement?
0
 

Author Comment

by:IncognitoMan
ID: 33549903
Yes, but its a lot of coding for this little problem and sounds stupid. It's like to go from Russia to Germany and take the shortcut to USA :D.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Iteration: Iteration is repetition of a process. A student who goes to school repeats the process of going to school everyday until graduation. We go to grocery store at least once or twice a month to buy products. We repeat this process every mont…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question