Given LCID and char codes, how to convert to Unicode?

O

Open Wound

X-No-Archive: yes

I am reading a file which contains non-latin characters. I know the
character code, and I know the LCID. Is there a function that I can
call to convert the character codes into Unicode?
 
J

Jay B. Harlow [MVP - Outlook]

Open,
How are you reading the file?

I would recommend a StreamReader, passing in the correct Encoding object as
a parameter.

Dim path As String = "test.txt"

Dim lcid As Integer
Dim encoding As System.Text.Encoding =
System.Text.Encoding.GetEncoding(lcid)

Dim reader As New StreamReader(path, encoding)

My only concern is, is the LCID ever different then the code page? (I'm use
to code pages not LCIDs. A couple hits on MSDN suggests that LCID = code
page.

If you have an array of bytes, you can use the methods on the above Encoding
object to covert to & from Char & String.

Hope this helps
Jay
 
J

Jay B. Harlow [MVP - Outlook]

Doh!

I gave a VB.NET sample, here is C# code :)

String path = "test.txt";
int lcid = 37;
System.Text.Encoding encoding = System.Text.Encoding.GetEncoding(lcid);
StreamReader reader = new StreamReader(path, encoding);

Note StreamReader is in the System.IO namespace.

Hope this helps
Jay
 
M

Mattias Sjögren

I am reading a file which contains non-latin characters. I know the
character code, and I know the LCID. Is there a function that I can
call to convert the character codes into Unicode?

I'd try something like this

CultureInfo ci = new CultureInfo( lcid );
Encoding enc = Encoding.GetEncoding( ci.TextInfo.ANSICodePage );
string s = enc.GetString( charCodes );



Mattias
 
J

James D. Beine

Hello,

Have a look at System.Text.Encoding namespace:

http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/cpref/html/frlrfsystemtextencodingclasstopic.asp

I hope this helps.

Best Regards,

Jamie

James D. Beine - President
Prodev Studios

Blog: ProdevStudios.com/blog
Internet Portal: ProdevStudios.com
Email: (e-mail address removed)
Toll Free: 800-577-0482
Direct: 270-444-0073
Fax: 270-444-6525
 
J

Jay B. Harlow [MVP - Outlook]

Mattias
Thanks! I knew I was missing a piece in my post. :)

CultureInfo

Jay
 

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