Back to Blog
Back to Blog
VuGen Custom Function: Left() (leftmost characters)
Posted on Aug, 2012 by Admin
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.