| |

VerySource

 Forgot password?
 Register
Search
View: 822|Reply: 5

Help: How to deal with ansi-encoded strings in .net?

[Copy link]

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-3-18 17:00:01
| Show all posts |Read mode
FCL provides UTF7Encoding, UTF8Encoding, ASCIIEncoding, UnicodeEncoding, four kinds of codecs, can not correctly decode ansi encoding (multi-byte string), what should I do?
Reply

Use magic Report

0

Threads

20

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 LAN

Post time: 2020-6-21 19:30:02
| Show all posts
What language is stored in your file? (Chinese? Japanese?)
Reply

Use magic Report

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-6-22 00:15:01
| Show all posts
Ansi-encoded string, that is, multi-byte, English is represented by one byte, and Chinese and other languages ​​are represented by double bytes
Reply

Use magic Report

0

Threads

20

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 LAN

Post time: 2020-6-22 22:30:01
| Show all posts
What language is written in ansi, which language is used to decode, personally think that it is only related to the operating system
Such as Chinese system
StreamReader sr=new StreamReader(@"d:\test.txt",Encoding.GetEncoding("gb2312"));
//gb2312 is the system language encoding when saving
Reply

Use magic Report

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-7-3 15:45:01
| Show all posts
Thank you! Use Encoding.Defalut to get the encoding associated with the default ANSI code page in the system locale.
But what if you want to go further and determine which encoding to use for the string?
Reply

Use magic Report

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-7-3 16:45:01
| Show all posts
As in ie, the encoding method can be selected automatically. But to be precise, I don’t know if there is such a possibility, or how likely is the automatic selection of ie (except gb2312 and unicode, unicode is mostly with a byte order mark)
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list