Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# String With Cyrillic Digits To Byte Array

Posted on 2010-08-27
18
Medium Priority
?
4,115 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

670 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