Back to Blog

VuGen Custom Function: Right

Today’s posting comes courtesy of Brian Wilson of TechSouth Consulting. This is a completely working example of Right() (rightmost characters) 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* Right(char* String, char* TempBuffer, int Nr)
 {
 if(strlen(String) >= Nr)
 {
 strcpy(TempBuffer, &String[strlen(String) - Nr]);
 TempBuffer[Nr] = '\0';
 return TempBuffer;
 }
 else return String;
 }

int vuser_init()
 {
 char MyString[] = "1234567890";
 char TempBuffer[11];
 lr_output_message("MyString: %s\n", MyString);
 lr_output_message("Right(4): %s\n", Right(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): Right(4): 7890
Ending action vuser_init.

 

Back to Blog