Honored Contributor.
Honored Contributor.

Hexadecimal conversion


I need to convert \x2d to -- and i tried using web convert param. doesn't work.

 I tried as below as well. I was able to convert ,but not for dynamic value. Any suggestion on how to handle hexadecimal values in LR?


lr_save_string("tjIAKJprJ\\x2FxoK2GJL\\x2BZMhgUm9Wat4j16dw\\x2B7o4d9Lak\\x3D", "hex_data");





Labels (1)
1 Reply
Acclaimed Contributor.. Acclaimed Contributor..
Acclaimed Contributor..

Re: Hexadecimal conversion

@snpsweb_convert_param does not the job. The help is clear on what it does. Here a function that I use

// convert_hex_string converts any \xNN character to its char-repressentation.
// The converted string is stored in the given parameter.
// arguments:
//   hex:       Input string to convert. The string is first evaluated 
//              for LR parameters
//   param:     The parameter that will receive the result.
// Example:
//   lr_save_string("\\x253aMD...","P1");
//   convert_hex_string("\\x25__{P1}__\\\\xZZ", "P2");
//   Saving Parameter "P2 = %__%3aMD...__\xZZ_".
// Note:
// This code is not bullet prove. It will fail if you have something like \xzz,
// but \xzz should have been encoded as \\xzz any way.
void convert_hex_string( char *hex, char *param ) 
    char    *buf, *s, *d;
    // Result of lr_eval_string is just a local buffer that will be freed after Iteration
    // This process will make string only shorter or keep the same size so no issue to 
    // use the result of lr_eval_string as tmp-buffer.
    buf = s = d = lr_eval_string( hex );
    while( *s ) {
        if ( *s == '\\' ) {
            if( *(s+1) == 'x' ) {
                int i;
                s++; s++;    // skip backslash and x
                if ( *s > '9' ) { i = *s - 'A' + 10; } else { i = *s - '0'; }
                i *=  16;    // make this most significant nibble
                s++;         // second hex digit
                if ( *s > '9' ) { i += *s - 'A' + 10; } else { i += *s - '0'; }
                *s = (char) i; // overwrite second digit with converted value.
            } else if( *(s+1) == '\\' ) {
                s++;     // Skip one backslash of the double backslash
        *d++ = *s++;     // copy source to destination and advance
    *d = *s;  // Copy null byte
    lr_save_string(buf, param);


Reward community members who take time to respond and help.
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.