Convert a number to text

Another Mark Sibley function.

This converts a number into text. It relies on the number already being saved as a character string.

It’s currently set to create a title case word but could be amended to create an all upper or lower case word easily enough.

The words it creates are going to be mostly nonsense, however because it could have occasionally created a real word I removed all of the vowels to reduce the likelihood of creating any offensive words.

Copy and paste the following into a LoadRunner script to see it in action.

int ConvertNumberToText(char * sInput)
{
int i;
int c;
char n;
char sText[50];
char sCharacter[10];
char * sUpper[10];
char * sLower[10];

sUpper[0] = “B”; sUpper[1] = “C”; sUpper[2] = “D”; sUpper[3] = “F”; sUpper[4] = “G”;
sUpper[5] = “H”; sUpper[6] = “J”; sUpper[7] = “K”; sUpper[8] = “L”; sUpper[9] = “M”;

sLower[0] = “b”; sLower[1] = “c”; sLower[2] = “d”; sLower[3] = “f”; sLower[4] = “g”;
sLower[5] = “h”; sLower[6] = “j”; sLower[7] = “k”; sLower[8] = “l”; sLower[9] = “m”;

for (i = 0; i < strlen(sInput); i++) {

sscanf(sInput+i,”%c”,&n);
sprintf(sCharacter,”%c”,n);
c = atoi(sCharacter);

// This ensures that the first character is an upper case letter and that the rest are lower case.
// If you want a word that is either all upper or lower case then amend the appropriate [sUpper] or [sLower]
if (i == 0) {strcpy(sText,sUpper[c]);}
else  {strcat(sText,sLower[c]);}
}

lr_save_string(sText,”sName”);
lr_output_message(lr_eval_string(“Output:[{sName}]”));
}

Action()
{
int p = 459332;
char string[50];

itoa(p,string,10);

lr_save_string(“50328″,”sNumber”);

ConvertNumberToText(string);
ConvertNumberToText(“2168”);
ConvertNumberToText(lr_eval_string(“{sNumber}”));

return 0;
}

 

Reverse a text string in LoadRunner

Another Mark Sibley C/LoadRunner function.

This function takes a string of text and reverses it, turning [Peter Piper] into [repiP reteP]. I know it will have limited use but should you need it then here it is.

Copy and paste the following into a LoadRunner script to see it work:

//*******************************************************
int Reverse (char* Param, char* PName)
{
char n, Character[2000], Varname[2000];
char FullString[2000];
int i = strlen(Param);

strcpy(FullString,””);
strcpy(&n,””);

while (i >= 0)
{
sscanf(Param+i, “%c”, &n);
sprintf (Character,”%c”,n);

strcat(FullString, Character);

i–;
}

lr_save_string(FullString,PName);
}
//*******************************************************

Action()
{
lr_save_string(“ABC123456″,”Param”);
Reverse(lr_eval_string(“{Param}”),”NewParam”);
lr_output_message(lr_eval_string(“Changed [{Param}] to [{NewParam}]”));

lr_save_string(“Peter Piper”,”Param”);
Reverse(lr_eval_string(“{Param}”),”NewParam”);
lr_output_message(lr_eval_string(“Changed [{Param}] to [{NewParam}]”));

lr_save_string(“Fiddlesticks”,”Param”);
Reverse(lr_eval_string(“{Param}”),”NewParam”);
lr_output_message(lr_eval_string(“Changed [{Param}] to [{NewParam}]”));

return 0;
}

Using strstr in LoadRunner

Brought to you by Mark Sibley.

The following is an example of how you can use the standard C function [strstr] within a LoadRunner script as a means of searching through long strings of text for the occurrence of any matching string. It has two examples that demonstrate how to use the output to do one of two things depending on whatever it is you want it to do.

A sample script can be downloaded here.
STRSTR.zip

Action()
{

// This creates an integer I decided to call [occurrence] and gives it a value of zero
int occurrence = 0;

// This creates a long string of text and then stores it in a parameter I’ve called {sLongString}
// In a real script you wouldn’t need this as you’d be searching through text that you’d captured.
lr_save_string(“peter piper picked a peck of pickled peppers”,”sLongString”);

//**************************************************
// Example 1:
// This is searching for the occurrence of [Poland] anywhere within the parameter {sLongString}
occurrence = strstr(lr_eval_string(“{sLongString}”),”Poland”);
if(occurrence != 0)
{
lr_output_message(“1) The string was found”);
}
else
{
lr_output_message(“1) The string was NOT found”);
}
//**************************************************

//**************************************************
// Example 2:
// This is searching for the occurrence of [peck] anywhere within the parameter {sLongString}
occurrence = strstr(lr_eval_string(“{sLongString}”),”peck”);
if(occurrence != 0)
{
lr_output_message(“2) The string was found”);
}
else
{
lr_output_message(“2) The string was NOT found”);
}
//**************************************************

return 0;
}