Custom find and Replace functions in LoadRunner

Source: Internet
Author: User

There is no direct function in the GLOBAS.H definition//loadrunner that supports finding and replacing strings, so you can encapsulate a lr_replace function://-------------------------------------------  ---------------------------------Char *strreplace (const char *SRC, const char *from, const char *to) {char *value;  Char *dst;  Char *match;  int size;  int Fromlen;  int Tolen;  size = strlen (src) + 1;  Fromlen = strlen (from);    Tolen = strlen (To);  Value = (char *) malloc (size);  DST = value;    if (value = NULL) {for (;;)      {match = (char *) strstr (SRC, from);        if (match! = NULL) {size_t count = match-src;        Char *temp;        Size + = Tolen-fromlen;        temp = (char *) realloc (value, size);          if (temp = = NULL) {free (value);        return NULL;        } DST = temp + (dst-value);        Value = temp;        Memmove (DST, SRC, count);        src + = count;        DST + = count;        Memmove (DST, to, Tolen);        src + = Fromlen;      DST + = Tolen; } else {strcpy (DST, SRC);      Break }}} return value;} // ----------------------------------------------------------------------------// -------------------------------  ---------------------------------------------int lr_replace (const char *lrparam, Char *findstr, char *replacestr) {int  res = 0;  Char *result_str;  Char lrp[1024];  sprintf (LRP, "{%s}", Lrparam);  Result_str = Strreplace (lr_eval_string (LRP), findstr, REPLACESTR);    if (result_str! = NULL) {lr_save_string (result_str, Lrparam);    Free (RESULT_STR);  res = 1; } return res;

Defined in action:

Login () {lr_save_string ("This is a string", "Mypar"),//web_convert_param ("Mypar",//                   "Sourceencoding=plain",//                   "Targetencoding=url", last); Lr_output_message ("%s", Lr_eval_string ("{mypar}")),//lr_replace ("Mypar", "+", "%20"),//lr_output_message ("%s", Lr_ Eval_string ("{mypar}"); Lr_replace ("mypar", "ing", "Mong Tsai");   Replace the ING string in Mypar with Wangzai lr_output_message ("%s", Lr_eval_string ("{mypar}"));

Custom find and Replace functions in LoadRunner

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.