Key points in solving MP3 tag garbled characters in JNI calls: setlocale

Source: Internet
Author: User

In the previous article:



If the ASCII code is directly converted:

Result = (ENV)-> newstringutf (STR );

If it contains Chinese characters:
Int length = mbstowcs (wchar_t * wcstr, const char * mbstr, size_t count );

The third parameter count of this function must be twice the length of mbstr,Otherwise, Chinese characters are garbled.

.



To use mbstowcs, you must set locale correctly. Simply write setlocale (lc_all, ""); can the current language environment support all encoding characters?



General locale "zh_CN.UTF-8" in Linux"



UTF-8 is encoding, en_US.UTF-8, zh_CN.UTF-8 is called character set, that is to say, 'A', 'B', 'medium', 'country 'and other corresponding integer, en_us and zh_cn is also the language environment
The number of characters contained in the en_US.UTF-8 and zh_CN.UTF-8 is basically the same, about 70 thousand Chinese characters, encoding is UTF-8 encoding, character set is
Unicode, the character sets of zh_cn.gb18030 and zh_cn.gbk are both Unicode 3
Is equivalent
The difference in the language environment is another thing. Chinese and foreign people express time, numbers, and habits are different, so they must be separated.

Most programs choose whether the language of the interface is Chinese or English based on the language environment variables.

 

Below are some outputs on the console >>>>>
View the installed language packs:
# Locale-





View the current settings:
# Locale





Modify settings:
# Export lc_all = ZH_CN.UTF-8


 



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.