LoadRunner string processing-padded string

Source: Internet
Author: User

There are times when you need to use 0 in front of a string in order to meet the formatting requirements of the length.

A function can be encapsulated in LoadRunner to handle this problem:

/*

Function to pad a string to x characters adding the required character at the start of the string

(Note string length Limited by length of the array)

Author:steven Woodcock, Sopra Group

Inputs:

Strchartopad-the String, requires to is padded out i.e. "123456"

Cparamname-the name of the parameter you want the end value to being saved to

Ivallength-the length you want the string to is padded out to i.e. 9

Cvaluetoadd-the character you want to pad the string out with, must is a single character i.e. "0"

Outputs:

Creates a LoadRunner parameter of a name specified in the input ' cParamName '

*/

int Lr_padstr (char* cchartopad, char* cparamname, int ivallength, char* cvaluetoadd) {

Char ctemp[1024] = "";

int iLoop = 0;

int imainloop = 0;

int isubloop = 0;

for (imainloop = 0; imainloop < ivallength; imainloop++) {

if (Imainloop = = strlen (Cchartopad)) {

ILoop = Ivallength-imainloop;

for (isubloop = 0; isubloop < ILoop; isubloop++) {

strcat (Ctemp, Cvaluetoadd);

}

}

}

strcat (Ctemp, Cchartopad);

Lr_save_string (Ctemp, cParamName);

}

LR_PADSTR can make a specified length of a character before the specified string, and then save the modified string in the LoadRunner parameter. Put the above code in the Lr_padstr.h header file and reference it in the LoadRunner script:

#include "Lr_padstr.h"

Action ()

{

For the LR_PADSTR function

char * cshortvalue = "123";

For the sprintf function

Char cpaddedvalue[8] = "";

int ishortvalue = 123;

int i;

The Lr_padstr function, written by Steven Woodcock can is used to pad with zeroes

Lr_padstr (Cshortvalue, "Ppaddedparameter", 8, "0");

Lr_output_message ("Padded value is%s", lr_eval_string ("{ppaddedparameter}"));

The Padtox function can also is used to pad with other characters (e.g. x)

Lr_padstr (Cshortvalue, "Ppaddedparameter", 8, "X");

Lr_output_message ("Padded value is%s", lr_eval_string ("{ppaddedparameter}"));

return 0;

}

Reference:

http://www.bish.co.uk/~richardmjbishop/index.php?option=com_content&view=article&id=85% 3asample-loadrunner-script-pad-a-string-with-leading-zeroes&catid=34%3arecent&itemid=1

LoadRunner string processing-padded string

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.