Asp.net C # solve the problem of supporting Chinese (or UTF8) operations

Source: Internet
Author: User

Solve the problem that manzana supports Chinese (or utf8) operations

At the beginning, I studied for a long time and focused on conversion of character encoding. I used many methods to convert the Chinese file names passed back by itunesmobiledevice to utf8 or gb2312. It is found that there is no problem in converting gb to utf8, but an error occurs when utf8 to gb. When the number of characters in the string to be converted is an odd number, a question mark "?" is often displayed. Or something. This problem does not occur if it is an even number. I found a lot of information on the internet and found several people had this problem. One of them spent a year, but they did not solve it. My heart is chilling, and I don't need to think about it any more when I get started. After one day and one night, I finally gave up. I think there is a loss of data when utf8 is converted to gb. Because utf8 is large, this problem cannot be solved.

There was nothing to do a few days ago and I began to think about it again. This time I started to study the functions of itunesmobiledevice. I found that manzana passed the itunesmobiledevice function with the string parameter.

 
[Dllimport (dllname, charset = charset. ansi, callingconvention = callingconvention. cdecl)]
Unsafe public extern static int afcfileinfoopen (void * conn, string path, ref void * dict );

 

I think the path passed in is byte [], so itunesmobiledevice should be recognizable. I tried it. The result is OK !!!! So excited !!!!!!!!!! Later, I changed all other string parameters to byte [], and then my file management function was done. The following is a function.

Unsafe public static int afcdirectoryread (void * conn, void * dir, ref byte [] buffer)
{
Int ret;
Void * ptr = null;
Ret = afcdirectoryread (conn, dir, ref ptr );
If (ret = 0) & (ptr! = Null ))
{
Intptr ipptr = new intptr (ptr );
Arraylist bufferarray = new arraylist ();
Int curr = 0;
While (true)
{
Byte tmpbyte = marshal. readbyte (ipptr, curr );
If (tmpbyte! = 0)
{
Bufferarray. add (tmpbyte );
Curr ++;
}
Else
{
Break;
}
}
Buffer = (byte []) bufferarray. toarray (typeof (byte ));
}
Else
{
Buffer = null;
}
Return ret;
}


I come to the conclusion that when using c # to call an unmanaged dll, it is best to use byte [] instead of string to operate the characters.

Now I can use my class to operate the file system on ios. Next, I will add the function of copying the converted ipa directly to the installous directory in pxlipafactory.

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.