Convert Encoding Format of a String
You can manually convert a string from one encoding to another (UTF-8, Unicode, or locale machine encoding) using the lr_convert_string_encoding function with the following syntax:
lr_convert_string_encoding(char * sourceString, char * fromEncoding, char * toEncoding, char * paramName)
The function saves the result string (including its terminating NULL) in the third argument, paramName. It returns a 0 on success and -1 on failure.
The format for the fromEncoding and toEncoding arguments are:
In the following example, lr_convert_string_encoding converts "Hello world" from the system locale to Unicode.
Action() { int rc = 0; unsigned long converted_buffer_size_unicode = 0; char *converted_buffer_unicode = NULL; rc = lr_convert_string_encoding("Hello world", NULL, LR_ENC_UNICODE, "stringInUnicode"); if(rc < 0) { // error } return 0; }
In the replay log, the output window shows the following information:
Output: Starting action Action. Action.c(7): Notify: Saving Parameter "stringInUnicode = H\x00e\x00l\x00l\x00o\x00 \x00w\x00o\x00r\x00l\x00d\x00\\x00" Ending action Action.
The result of the conversion is saved to the paramName argument.