Encoding for windows application?

  • Thread starter Thread starter Iwan Petrow
  • Start date Start date
I

Iwan Petrow

Hi,

I want for my application to set an exact encoding for converting byte
arrays to strings and for reading from files.
I can create an encoding instance with exact codepage and to work with
it.
Are there another ways to do this? Or any way to set the default
encoding for entire application (only the application)?

Thanks.
 
Iwan,

AFAIK, there is no way to set this and have all the APIs pick up on it.
What I would do is create a static property that you can expose from one of
your libraries which will get the particular encoding, and then use that to
pass the encoding to the appropriate APIs. Most of the APIs that are
encoding dependent have an overload which will allow you to specify the
encoding, so I wouldn't worry about not being able to get at it. Of course,
unless, you have a situation already where you can't specify the encoding
(in which case, what is it?)

Hope this helps.
 
Hi,

My problem is that I have files with symbols with ASCII codes between
128 and 255. I read these and after that I save file contents to a
database. And first I want to show these symbols in a textbox control.
These symbols are converted to different unicode symbols depending on
windows settings (I can't remeber exactly where but may be language
settings). May be I have to set an exact culture to my application.
 
Iwan Petrow said:
My problem is that I have files with symbols with ASCII codes between
128 and 255.

No you don't - there are no such ASCII characters. ASCII has no values
over 127.
I read these and after that I save file contents to a
database. And first I want to show these symbols in a textbox control.
These symbols are converted to different unicode symbols depending on
windows settings (I can't remeber exactly where but may be language
settings). May be I have to set an exact culture to my application.

You should use Encoding.Default if you want the system default
encoding.
 
When I open the file with hex editor I see values between 128 and 255.
And according encoding these symbols are read differently.
 
Iwan Petrow said:
When I open the file with hex editor I see values between 128 and 255.
Yes.

And according encoding these symbols are read differently.

Exactly. Different encodings will give you different Unicode characters
for those bytes.

Now, have you tried using Encoding.Default, and have you read the
article I referred you to?
 
Back
Top