Resource icon

String Manipulation in loadrunner Using Strtok

  • perf-test.com need your contributions to build up a strong repository of performance engineering resources.

Example 1: Breaking the string into multiple parts as specified by a delimiter. See the following example where we are breaking the string by a delimiter ":"

Code:
Action()
{
   
    char str[80] = "We love: SPEForums.com";
       const char s[2] = ":";
       char *token;
   
       /* get the first token */
       token = (char *)strtok(str, s);
       lr_output_message("The first output is %s", token);
   
       /* walk through other tokens */
       while( token != NULL )
   {
      token = (char *)strtok(NULL, s);
      lr_output_message("The Second output is %s", token);
   }
   
    return 0;
}

Output Of Above Code:

Code:
Starting action Action.
Action.c(10): The first output is We love
Action.c(16): The first output is  SPEForums.com
Action.c(16): The first output is (null)
Ending action Action.

Example 2: Multiple Delimiters - "-" and ":"

Code:
    char str[80] = "We love: SPEForums.com we are -performance engineers";
       const char s[3] = "-:";
       char *token;
   
       /* get the first token */
       token = (char *)strtok(str, s);
       lr_output_message("The first output is %s", token);
   
       /* walk through other tokens */
       while( token != NULL )
   {
      token = (char *)strtok(NULL, s);
      lr_output_message("The Second output is %s", token);
   }

Response of example 2

Code:
Starting action Action.
Action.c(10): The first output is We love
Action.c(16): The Second output is  SPEForums.com we are
Action.c(16): The Second output is performance engineers
Action.c(16): The Second output is (null)
Ending action Action.
Author
admin
Views
72
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from admin