1. 程式人生 > >C語言對字符串進行轉義excape操作的代碼

C語言對字符串進行轉義excape操作的代碼

++ code 幫助 != turn cas 進行 urn null

把做工程過程比較重要的一些內容片段做個珍藏,下面內容內容是關於C語言對字符串進行轉義excape操作的內容,希望對大夥有些幫助。

{

    int i = 0, j;

    while( i < data_len ){
        if( ‘%‘ != data[i]){
            strncat(buf, data+i, 1);
            i++;
            continue;
        }

        j = 0;
        while( NULL != transfer_table[j][1] ){
            if( 0 == strncasecmp(data+i+1, transfer_table[j][1], 2 )){
                strncat(buf, transfer_table[j][0], 1);
                i += 3;
                break;
            }
            j++;
        }
        if( NULL == transfer_table[j][1] ){
            strncat(buf, data+i, 1);
            printf("escape_url_character: unhandled sequence: %sn", data+i);
            i++;
        }
    }

    memset(data, 0, data_len);
    strcpy(data, buf);

    free(buf);
    return 0;
}

C語言對字符串進行轉義excape操作的代碼