Tuesday, April 07, 2009

Loadrunner: How to insert a charactor(s) into a string

I want to replace the '\' into '\\' in one string, here is my implementation in Loadrunner:


char * position;
int i=0;
int j=0;
Char * SRanStatus2_backup;
Char SRanStatus2[50]="abcc\dada-com";

SRanStatus2_backup= (char *)malloc(50 * sizeof(char));

memset(SRanStatus2, 0, sizeof(SRanStatus2));

memset(SRanStatus2_backup, 0, sizeof(SRanStatus2_backup));

position = SRanStatus2;

while ((*position)!= NULL) {

if ((*position)!='\\') { //if ((*position)!='\x07') {

SRanStatus2_backup[j]=SRanStatus2[i];
i++;
j++;
}

else if ((*position)=='\\') { //else if ((*position)=='\x07') {
SRanStatus2_backup[j]='\\';
SRanStatus2_backup[j+1]='\\';
j=j+2;
i++;
}

position++;
}

SRanStatus2_backup[j]='\0';

lr_save_string(SRanStatus2_backup, "CheckboxORD_2_backup");

free(SRanStatus2_backup);
free(SRanStatus2);

return 0;

No comments:

Post a Comment