Java – from basic_ Convert string to jstring
•
Java
I'm using basic_ string< wchar_ t> Input and need to be converted to jstring to pass through the JNI layer I wonder what the best way is I have a function from my basic_ string< wchar_ t> Give me an STD:: string Type, so the answer is also cool
Cheers@ H_ 419_ 3@
Solution
You need to add STD:: Basic_ Convert string to UTF-8 Look at your wstring – > string conversion
Sun has a JNI tutorial that shows how to convert char * to jstring (using some UTF conversion routines) You can use your wstring - > string, and then string c_ Str() passed to newString UTF function: @ h_ 419_ 3@
Untested Code: @ h_ 419_ 3@
JNIEXPORT jstring JNICALL StringTest(jnienv *env) { const char* test = "something"; return (*env)->NewStringUTF(env,test); }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码