2
Comme vous pouvez le voir, je reçois jbyte * str forme la chaîne utf. Alors chaque caractère de chaîne a deux jbytes sinon un octet?Dans la programmation Android Ndk obtenir la chaîne UTF
JNIEXPORT jstring JNICALL
Java_Prompt_getLine(JNIEnv *env, jobject obj, jstring prompt) {
char buf[128];
const jbyte *str;
str = (env)->GetStringUTFChars(env, prompt, NULL);
if (str == NULL) {
return NULL;/OutOfMemoryError already thrown */
}
printf("%s", str);
(*env)->ReleaseStringUTFChars(env, prompt, str);
/* We assume here that the user does not type more than * 127 characters */
scanf("%s", buf);
return (*env)->NewStringUTF(env, buf);
}
Non! Le tableau renvoyé par 'GetStringUTFChars' est un caractère Unicode dans un encodage UTF-8 modifié. Chaque personnage prendra de un à six octets. Si vous voulez un jeu de caractères/encodage avec un octet par caractère, utilisez une surcharge 'String.getBytes' ou la classe' Charset'. –