Friday, June 7, 2013

How to convert plain text into hexadecimal and octal formats in Loadrunner?

I already have explained how to use web_convert_param function. In this post I will write about how to convert plain test to hexadecimal format. I once used this for encoding a string.

char *PlaintoHexadecimal(const char *InputS, char *OutputS)

                int i;
                char CurrentChar;
                char CurrentStr[4] = {0};   
                OutputS[0] = '\0'; 
                for (i = 0; CurrentChar = InputS[i]; i++)  
                                sprintf(CurrentStr, "%X", CurrentChar);          
                                strcat(OutputS, CurrentStr);   
            return OutputS;

char InputS[] = "This is plain string";
char OutputS[100];

lr_output_message("The input is %s",InputS);
lr_output_message("The output is %s", PlaintoHexadecimal(InputS, OutputS));

return 0;


Once you execute the above code, the string will be converted to hexadecimal format as shown below:

Wow Done!!!! Now how to convert the plain text in octal format?
Just change the X factor to o factor ;). I am not kidding. You just have to change the below string

sprintf(CurrentStr, "%X", CurrentChar);        to     sprintf(CurrentStr, "%o", CurrentChar);          

Hope you will execute that and see what happens. I got this:
Click here to know more

Thank you so much for reading and following.

No comments:

Post a Comment