3

I have the following code to convert a String to a CFString and backwarts:

string path = @"C:\Users\ayi\Desktop\Failed\AngryBirds.ipa";

IntPtr p_path = __CFStringMakeConstantString(path);

CoreFoundation.CFString cfstring = new CoreFoundation.CFString(p_path);

string result = cfstring.ToString();

The problem is path != result where the path contain some Chinese characters like @"C:\Users\ayi\Desktop\中文\AngryBirds.ipa";

How can I cast string that contain Chinese to cfstring in C#?

1

1 Answer 1

0

You can convert a c-like string to CFString with the CFStringCreateWithCString function:

CFStringCreateWithCString(kCFAllocatorDefault, myCString, kCFStringEncodingUTF8);

Then you need to figure-out how to convert C# String to c-like string. I am unfortunately not a C# developer, so here is a link which seems ok:

C++ .NET convert System::String to std::string

Note: use std::string::c_str() to convert C++ string to c-like string myCppString.c_str(). This operation is mostly accessing inner memory, so very fast.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.