Share this page

# lr_convert_string_encoding

Converts a string to a different encoding.

    int lr_convert_string_encoding( char *sourceString, char *fromEncoding, char *toEncoding, char *paramName );

Alphabetical Listing - C Language Utility Functions

## Arguments

Name | Comments
--- | ---
sourceString | The string to convert
fromEncoding | The encoding of the sourceString
toEncoding | The encoding to convert of the string saved in parameter paramName
paramName | The name of the parameter in which the destination string will be saved

lr_convert_string_encoding converts a string encoding between the following encodings: System locale, Unicode, and UTF-8. The function saves the result string, including its terminating NULL, in the parameter paramName.

Printable characters in the result string are displayed in VuGen and its logs as the actual characters. Non-printable characters are displayed in Hexadecimal. For example:

    rc = lr_convert_string_encoding("A", NULL, LR_ENC_UTF8, "stringInUnicode");

The result string displays as A\x00, and not \x41\x00, because the letter A is a printable character.

Add lr_convert_string_encoding manually to a script when needed. It is not recorded.

Values for 'fromEncoding' and 'toEncoding
Constant | Value
--- | ---
LR_ENC_SYSTEM_LOCALE | NULL
LR_ENC_UTF8 | "utf-8"
LR_ENC_UNICODE | "ucs-2"

## Return Values

This function returns 0 on success and -1 on failure.

## Parameterization

All arguments can be parameterized using standard parameterization.

## Example

In the following example, lr_convert_string_encoding converts the string "Hello world" from the system locale to Unicode.

Note: The output displays printable characters as the characters themselves, followed by their terminating NULLs. Non-printable characters would be displayed in Hexadecimal.

    Action() {
    	 int rc = 0;
    	unsigned long converted_buffer_size_unicode = 0;
    	char *converted_buffer_unicode = NULL;
    	rc = lr_convert_string_encoding("Hello world",
                 LR_ENC_SYSTEM_LOCALE, LR_ENC_UNICODE, "stringInUnicode");
    	if(rc < 0) {
                // error
    	}
    	return 0;
     }

    Example: Output:
    Starting action Action.
    Action.c(7): Notify: Saving Parameter "stringInUnicode = H\x00e\x00l\x00l\x00o\x00 \x00w\x00o\x00r\x00l\x00d\x00\x00\x00"
    Ending action Action.

Tips to improve your search results... VuGen Function Reference Version 26.1 Function Reference 26.1 All View Local Help Center View Online Help Center Version: