VuGen: Replace Special Characters

This function (called EncodeText) may be a bit out of date, but can be used to replace special characters and use different encoding. You could put this in the very top of the vuser_init section of your script, or in the globals.h or other include file.

//------begin code---------------
EncodeText(New,Orig)
char *New;
char *Orig;
{
    int New_index;
    int Orig_index;
    int len;
 
    len = strlen(Orig);
    New_index = 0;
    for (Orig_index=0;Orig_index<len;Orig_index++) {
        switch(Orig[Orig_index]) {
            case ' ':
            New[New_index] = '+';
            break;
            case '|':
            case '+':
            case '\\':
            case '?':
            case ':':
            case '[':
            case ']':
            case '(':
            case ')':
            case '^':
            case '~':
            case '`':
            case '{':
            case '}':
 
            New[New_index++] = '%';
            New[New_index++] = '0' + (int) (Orig[Orig_index] / 16);
            if ((Orig[Orig_index] % 16) < 10) {
                New[New_index] = '0' + (int) (Orig[Orig_index] % 16);
                } else {
                New[New_index] = 'A' + (int) (Orig[Orig_index] % 16) - 10;
            }
            break;
            default:
            if ((Orig[Orig_index] > 31) && (Orig[Orig_index] < 126)){
                New[New_index] = Orig[Orig_index];
                } else {
                New[New_index++] = '%';
                New[New_index++] = '0' + (int) (Orig[Orig_index] / 16);
                if ((Orig[Orig_index] % 16) < 10) {
                    New[New_index] = '0' + (int) (Orig[Orig_index] % 16);
                    } else {
                    New[New_index] = 'A' + (int) (Orig[Orig_index] % 16) - 10;
                }
            }
            break;
        }
        New_index++;
    }
    New[New_index] = 0;
}
//------end code---------------

What's Next?

Did you enjoy this article? Help spread the word by sharing:

Join the Northway Navigator Club today and get access to restricted content including our best tips and tricks. Membership is free! You will also receive free email updates by registering.

Engage in the conversation and leave a comment:

Scott Moore

About Scott Moore (153 articles)

With over 20 years of IT experience with various platforms and technologies, Scott has tested some of the largest applications and infrastructures in the world. He is a Certified Instructor and Certified Product Consultant in HP’s LoadRunner and Performance Center products. He currently holds HP certifications for ASE, ASC, and CI. A thought leader in the APM space, he speaks regularly at IT conferences and events