首页 > 代码库 > LoadRunner中字符串替换

LoadRunner中字符串替换

Action()
{
char dest[500]="";
char src[500]="%25E9%25AB%2598%25E4%25B8%25AD";
char oldstr[100]="%";
char newstr[100]="**";

char * position;
int stringlen=0;

//如果源字符串为空
if(strlen(src)==0)
{
return 0;
}

//如果源字符串不包含oldstr
position=(char *)strstr(src,oldstr);

if(position==NULL)
{
return 0;
}

while(position!=NULL)
{
stringlen=strlen(src)-strlen(position);
memset(dest,0,500);
strncpy(dest,src,stringlen);
strcat(dest,newstr);
position=position+strlen(oldstr);
strcat(dest,position);
strcpy(src,dest);
position=(char *)strstr(src,oldstr);
}

lr_output_message("%s",src);


return 0;
}

 想封装成动态链接库