Replace a character with word

682 views
Skip to first unread message

Kiran

unread,
Apr 4, 2012, 4:00:15 AM4/4/12
to LR-Loa...@googlegroups.com
Hi All,

Kindly help in fixing the below script.

Actually i want to replace "+" character in string to "%2B" in Loadrunner

Example: 
old String:  Kiran+Kumar
Replace: "+" to "%2B"
New string should be:  "Kiran%2BKumar"

My script:
/*****************************************

  char path[] = "cWZmxw0N/eHGagZ+PlAF55J/5J72dy2Y+/mVu9SCJIko"; 

    char separators[] = "+"; 

    char token, temp, *fullstr, str[10], value ;

char *text , *ltemp, *finalstr;

int i = 0, j;

    
    token = strtok(path, separators); 

/********** this part of script is split the text with delimiter as "+" ***********************
    while (token != NULL ) { 

i = i +1;

str [i] = token;

lr_output_message ("Str value: %d", str [i] ); 

               token = strtok(NULL, separators); 
        } 
/****************************************

/***********************this part to concatenate with "%2B"*********************  
for (j=1; j < i+1; j++) {

fullstr = fullstr + str[j];
lr_output_message ("Str value: %s", fullstr);
ltemp = (char *)strcat(fullstr, "%2B");
/*************************************************************

}

Part 2 is not working.
Welcome for other solution for the case.

Kindly help in fixing this. 

Thanks,
Kiran

umamahes wararao

unread,
Apr 4, 2012, 9:39:59 AM4/4/12
to lr-loa...@googlegroups.com
Hey instead of writing the below code directly you can use this function web_convert_param.

Correct me if i am wrong.

 


--
You received this message because you are subscribed to the Google "LoadRunner" group.
To post to this group, send email to LR-Loa...@googlegroups.com
To unsubscribe from this group, send email to
LR-LoadRunne...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/LR-LoadRunner?hl=en



--
With Cheers,

S.V.UmamaheswaraRao
Mobile: +91-9703606358

Kiran Kumar

unread,
Apr 4, 2012, 12:05:58 PM4/4/12
to lr-loa...@googlegroups.com
Hi Umamahes,

Thats good idea!!!

I will implement this and check. Final i got logic and did after spending more than 2 hrs.

Action()
{

 

    char path[] = "Ranjan+Kumar+Rajneesh" ;
    char separators[] = "+"; 
    char *token,*fullstr[100], *str[100], finalstr[100];
int i = 0, j;
char *A, *B, Final[100];

    token = (char *)strtok(path, separators);

while (token != NULL ) 
i = i +1;
str [i] = token;
token = (char *)strtok(NULL, separators); 
if (i > 1) {
A = str [i-1];
sprintf(finalstr,"%s%s",A,"%2B");
strcat(fullstr,finalstr);
// lr_output_message ("Str value: %s", fullstr);
}

for (j =i; j< i+1;j++) {
B = str[j];
strcat(fullstr,B);
}
lr_save_string((char*)fullstr, "Value");
return 0;
}

Thanks,
Kiran

Gaurav Mishra

unread,
Apr 4, 2012, 11:58:08 PM4/4/12
to lr-loa...@googlegroups.com
Hi kiran,
 
I got output of your function as ---------- >>>    Str value: Ranjan%2BKumar%2B
 
you need to concat 1 more time :P
 
anyways, that was a vry small point. good work.
 
1 more question have you insert it in your LR script. is it running fine then???
 
i think you need to delete you garbadge value else you shld get some error. if it is running fine then OK.
 
let me know
 
Thanks!

umamahes wararao

unread,
Apr 5, 2012, 8:20:33 AM4/5/12
to lr-loa...@googlegroups.com
Hi Kiran,

Instead of below logic, you can reduce your code in simple way, please find the below

char param1[256] = "cWZmxw0N/eHGagZ+PlAF55J/5J72dy2Y+/mVu9SCJIko";

 

lr_save_string(param1,"param2");

 

  lr_output_message(param1);

web_convert_param("param2", "SourceEncoding=PLAIN",  "TargetEncoding=URL", LAST );

 

   lr_output_message("%s",lr_eval_string("{param2}"));

Reply all
Reply to author
Forward
0 new messages