VuGen Custom Function: Left() (leftmost characters)

Today’s code is courtesy of Brian Wilson of TechSouth Consulting. This is a completely working example of a VuGen Left() (leftmost characters) function, just like you can do in VB. I’d create a library of functions like this in a header (.h file) and include them in your scripts where you’re doing string manipulation.

char* Left(char* String, char* TempBuffer, int Nr)
 {
 if(strlen(String) >= Nr)
 {
 strcpy(TempBuffer, String);
 TempBuffer[Nr] = '\0';
 return TempBuffer;
 }
 else return String;
 }
 
int vuser_init()
 {
 char MyString[] = "5551115151";
 char TempBuffer[11];
 lr_output_message("MyString: %s\n", MyString);
 lr_output_message("Left(4): %s\n", Left(MyString, TempBuffer, 4));
 
return 0;
 }

Here is what the VuGen execution output log might look like:

Virtual User Script started
Starting action vuser_init.
vuser_init.c(29): MyString: 1234567890
vuser_init.c(31): Left(4): 1234
Ending action vuser_init.

 

What's Next?

Did you enjoy this article? Help spread the word by sharing:

Join the Northway Navigator Club today and get access to restricted content including our best tips and tricks. Membership is free! You will also receive free email updates by registering.

Engage in the conversation and leave a comment:

Scott Moore

About Scott Moore (153 articles)

With over 20 years of IT experience with various platforms and technologies, Scott has tested some of the largest applications and infrastructures in the world. He is a Certified Instructor and Certified Product Consultant in HP’s LoadRunner and Performance Center products. He currently holds HP certifications for ASE, ASC, and CI. A thought leader in the APM space, he speaks regularly at IT conferences and events