Back to Blog

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---------------
Back to Blog