1. 程式人生 > >LoadRunner字串拼接函式strcat

LoadRunner字串拼接函式strcat

char*strcat(char*to,constchar*from);/將一字串追加到另一字串後面
示例
    lr_save_datetime("Today is %m月 %d日 %Y年 ", DATE_NOW, "today"); 

    // 輸出:today = Today is 03月 11日 2016年

    lr_save_datetime("Tomorrow is %m月 %d日 %Y年 ", DATE_NOW+ONE_DAY, "tomorrow"); 

    //輸出:tomorrow = Tomorrow is 03月 12日 2016年

    strcat(Temp,lr_eval_string("{today}"));//將變數today的值追加到Temp末尾

    lr_message("Temp=%s",Temp);//輸出:Temp=Today is 03月 11日 2016年

    strcat(Temp,lr_eval_string("{tomorrow}"));//將變數today的值追加到Temp末尾    
    lr_message("Temp=%s",Temp);    

    //輸出:Temp=Today is 03月 11日 2016年 Tomorrow is 03月 12日 2016年

看明白了嗎?

再來一個字串擷取函式+字串拼接函式的示例:
char *paperNum;
    char *year;
    char *month;
    char *day;
    char birthdate[200];
    char *str;

    
    //將441301198005059899儲存到變數paperNum中
    lr_save_string("441301198005059899","paperNum");

    //擷取變數paperNum中的年份
    lr_save_var(lr_eval_string("{paperNum}")+6,4,0,"year");

    //擷取變數paperNum中的月份
    lr_save_var(lr_eval_string("{paperNum}")+10,2,0,"month");

    //擷取變數paperNum中的日期
    lr_save_var(lr_eval_string("{paperNum}")+12,2,0,"day");

    //將-儲存到變數str中
    lr_save_string("-","str");

    strcat(birthdate,lr_eval_string("{year}"));
    strcat(birthdate,lr_eval_string("{str}"));
    strcat(birthdate,lr_eval_string("{month}"));
    strcat(birthdate,lr_eval_string("{str}"));
    strcat(birthdate,lr_eval_string("{day}"));

    lr_message("birthdate=%s",birthdate);//最後輸出:birthdate=1980-05-05

上面使用的strcat();函式還可以通過不斷巢狀,簡寫,如下

strcat(strcat(strcat(strcat(strcat(birthdate,lr_eval_string("{year}")),lr_eval_string("{str}")),lr_eval_string("{month}")),lr_eval_string("{str}")),lr_eval_string("{day}"));

看明白了嗎?如果不懂
lr_save_var();函式的,請看我的另一篇日誌:LoadRunner如何使用lr_save_var擷取任意字串長度
希望對你有所幫助!