by Chandrakant

Categories

  • Performance Testing

Tags

  • LoadRunner
  • LoadRunner Scripting Tricks

There is an inbuilt function in loadrunner that can be used to capture data from string by specifying delimiters. strtok function can be used to do the trick -

In below example it is shown that how all words can be captured from string “http://localhost/app/myapp:8080” by using 2 delimeters / and :

 extern char * strtok(char * string, const char * delimiters ); // Explicit declaration

    char String_org[] = “http://localhost/app/myapp:8080”; // original string 

    char delimiter[] = “/:”;

    char * token;

    token = (char *)strtok(String_org, delimiter); // capture 1st sub string based on defined delimiter

    if (!token) {

        lr_output_message (“No tokens found in string!”);

        return( -1 );

    }

    while (token != NULL ) { // While valid tokens are returned

        lr_output_message (“%s”, token );

        token = (char *)strtok(NULL, delimiter); // Get the next token

    } 

 Output:

Starting iteration 1.

Starting action Action.

Action.c(15): http

Action.c(15): localhost

Action.c(15): app

Action.c(15): myapp

Action.c(15): 8080

Ending action Action.