标签:
如果按照普通的定义字符串就会出现以下错误:
解决方法如下:
将双引号改成单引号:
lr_searchReplace(abc,"test",‘ ‘,‘+‘);
Action也可以这些写:
void lr_searchReplace(char* inputStr, char* outputStr, char lookupChar, char repChar) { char *ptr =inputStr; char xchar; int len=0; int i=0; lr_output_message("%s",inputStr); xchar = *ptr;//Copy initial len=strlen(inputStr); while (len>0) { len--; xchar = *ptr; if(xchar==lookupChar) { inputStr[i]= repChar; } ptr++; i++; } lr_save_string(inputStr,outputStr); lr_output_message("%s",inputStr); } Action() { lr_save_string("chaitAgolyH789anya m bhatt", "InputName"); lr_output_message("替换前的字符串=%s",lr_eval_string("{InputName}")); lr_searchReplace(lr_eval_string("{InputName}"), "test",‘ ‘,‘+‘); lr_output_message("替换后的字符串=%s",lr_eval_string("{test}")); return 0; } Action() { char *abc; lr_save_string("chaitanya m bhatt", "InputName"); abc = lr_eval_string("{InputName}"); lr_searchReplace(abc,"test",‘ ‘,‘+‘); lr_output_message("替换前的字符串=%s",lr_eval_string("{InputName}")); lr_output_message("替换后的字符串=%s",lr_eval_string("{test}")); return 0; }
深圳湖北籍软件测试群 275212937
loadrunner通过C语言实现字符的替换(只能替换单个字符,慎用)
标签:
原文地址:http://www.cnblogs.com/qmfsun/p/4947432.html