LoadRunner get milliseconds and string substitution implementations

Source: Internet
Author: User

LoadRunner get milliseconds and string substitution implementations

Today make a Performance Testing, parameterization requires the creation of user names can not be repeated, think there is no good way to avoid the repetition of the user name.  So we want to use time + random number to achieve, but the implementation of a problem encountered. The name cannot contain. This particular character. So you have to deal with the. String, so you want a C language implementation of the string substitution function.  LoadRunner default no string substitution function, do not know why not do it? (1) The millisecond implementation method is created by creating the Date/time parameter and setting the format to:%y%m%d%h%m%s.000(2) Replace string functionChar *strreplace (char *dest, char *src, const char *OLDSTR, const char *NEWSTR, size_t len){ / * @param char* dest target string, which is the new string after replacement* @param const char* src source string, replaced by string* @param const char* OLDSTR old substring, sub-string to be replaced* @param const char* NEWSTR new sub-string* @param int len will be replaced by the first Len characters */ //Sub-string position pointerChar *needle;//Temporary memory areaChar *tmp;//If the strings are equal, return directlyif (strcmp (Oldstr, newstr) ==0) {return src;}//Assign the source string address to the pointer dest, i.e. let both dest and Src point to the memory area of SRCdest = src;//If a substring is found and the substring position is within the range of the front Len substring, the substitution is made, otherwise the direct returnWhile ((needle = (char *) strstr (dest, Oldstr)) && (needle-dest <= len)){ //Allocate new space: +1 is to add the '% ' terminator to the end of the stringtmp= (char*) malloc (strlen (dest) + (strlen (newstr)-strlen (OLDSTR)) +1);//Copy the data from the first needle-dest memory space in SRC to arrstrncpy (TMP, dest, needle-dest); //end of identification stringtmp[needle-dest]= ' + ';//Connect arr and newstr, that is, attach the newstr to the tail of arr, thus composing a new string (or character array) arrstrcat (TMP, NEWSTR);//Connect the section of SRC from the position of the OLDSTR substring to arr, forming a new string arrstrcat (TMP, Needle+strlen (OLDSTR)); //Copy the memory allocated with malloc to the pointer Retvdest = (char *) strdup (TMP);//Release malloc allocated memory spaceFree (TMP);}(3) Verifying function availabilityAction (){Char *str=lr_eval_string ("{Hm}");char *old= "\.";char *new= "";Char *dest;lr_error_message ("%s\n", Strreplace (dest, str, old, new,20));return 0;} The format of the output is: ACTION.C ($): error:20130827153554665after the implementation of the above, the basic can realize the login user name is not repeated phenomenon. OK!!!

LoadRunner get milliseconds and string substitution implementations

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.