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;
}

 

Author: Richard Bishop

http://about.me/richard_bishop