strtok – Capture a sub string or data from a string based on delimiters in Loadrunner

strtok – Capture a sub string or data from a string based on delimiters in Loadrunner

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.