String comparison function in LR


Thanks in advance,

Can any one help on string comparison function otherthan strcmp to use in Load Runner scripting.

I need to compare a string with the value captured and saved in LR variable.

For Example :  result=strcmp((lr_eval_string("{c_planGroupVal}"),"DC")

Please suggest me with an alternate string comparison function which can be used in LR script.


  • Greetings,

    LoadRunner use C commands and it can be programmatic solved by using the different C language commands and logic.

    Following next you have an example about how compare strings using the command strnicmp.


    Example: strnicmp

    The following example compares two strings, string1 and string2, which are nearly identical - string2 contains the word "one" instead of "the" and the word "dog" in uppercase instead of lowercase.

    stricmp returns an unequal comparison because it compares the whole string which includes the word imbalance "one" and "the". strnicmp compares 30 characters only, which falls short of the word imbalance in the strings. strnicmp also ignores the uppercase "DOG". It therefore returns an equal comparison.

        int result;
        char tmp[20];
        char string1[] = "The quick brown dog jumps over the lazy fox";
        char string2[] = "The quick brown DOG jumps over one lazy fox";
    // Perform a case sensitive comparison 
        result = stricmp( string1, string2 ); 
        if (result > 0)
            strcpy(tmp, "greater than");
        else if (result < 0)
            strcpy(tmp, "less than");
            strcpy(tmp, "equal to");
        lr_output_message ("stricmp: String 1 is %s string 2", tmp);
    // Compare 30 chars  
        result = strnicmp( string1, string2 , 30); 
        if (result > 0 )
            strcpy( tmp, "greater than");
        else if (result < 0)
            strcpy(tmp, "less than"); 
            strcpy(tmp, "equal to");
        lr_output_message ("strnicmp: String 1 is %s string 2", tmp);
    Action.c(17): stricmp: String 1 is greater than string 2
    Action.c(28): strnicmp: String 1 is equal to string 2
  • Hello there, you didn't tell what property of strcmp you didn't like.

    Does it help you to look on strcmp() like working just like substraction? Comparing two numbers, using substraction and zero, you get operations which resemble the usage of strcmp, as you can see here:

    5 - 4 > 0   (while strcmp("ccc", "bbb") > 0) i.e., first argument is larger than the second

    4 - 4 = 0 (while strcmp("bbb", "bbb") = 0) i.e., both arguments are equal

    3 - 4 < 0 (while strcmp("aaa", "bbb") < 0) i.e., first argument is less than the second


    As you notice, you get a positive, zero or negative result in both cases. Also, don't forget functions like strlen("some string") or strstr("haystack with needle and thread", "needle") to see if you have a string at all or if the second string is part of the first..