Use of string encoding for detection and conversion

Source: Internet
Author: User

Due to the working relationship, it is often necessary to obtain the encoding information of a string to prevent garbled characters. I found the following libraries online:

1. C #

Https://code.google.com/p/ude/ probe library

Ude is a C # port of Mozilla universal charset detector.
The original source code is available:
Http://mxr.mozilla.org/mozilla/source/extensions/universalchardet/src/
Http://www.mozilla.org/projects/intl/UniversalCharsetDetection.html
Http://mxr.mozilla.org/mozilla-central/source/extensions/universalchardet/doc/UniversalCharsetDetection.doc

2. Java

Http://code.google.com/p/juniversalchardet/

3. Python
Http://chardet.feedparser.org/

4. c ++

IBM has an open source library ICU, http://site.icu-project.org/Conversion

Linux

Enca: http://freecode.com/projects/enca probe and conversion Library

C ++ version of Mozilla code

Http://code.google.com/p/uchardet/ probe library

Reference

Http://blog.csdn.net/xian0617/article/details/6706107

Https://www.byvoid.com/blog/tag/mozilla

Http://www.linuxidc.com/Linux/2011-05/35769.htm

Http://blog.csdn.net/wangyonggang/article/details/927

Enca, uchardet, ICU, Ude,

 

 

-------------------

Import the Library:

Using ude;

And feed a stream or a byte array to the detector. Call dataend to sort y the detector that
You want back the result:

Icharsetdetector cdet = new charsetdetector ();
Byte [] buff = new byte [1024];
Int read;
While (read = stream. Read (buff, 0, Buff. Length)> 0 &&! Done ){
Cdet. Feed (buff, 0, read );
}
Cdet. dataend ();
Console. writeline ("charset: {0}, confidence: {1}, cdet. charset, cdet. Confidence );

Alternatively, you can feed a stream to the detector:

Using (filestream FS = file. openread (filename )){
Icharsetdetector cdet = new charsetdetector ();
Cdet. Feed (FS );
Cdet. dataend ();
Console. writeline ("charset: {0}, confidence: {1}, cdet. charset, cdet. Confidence );
}

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.