R. E. Cook
Home 
Contact Us 

Dr. Cook
Resume 

RunningShoes Library for WinRunner 
RunningShoes 

Custom WinRunner Functions 
and Utilities,
to Your Specs
Custom 

A Random Collection of WinRunner Solutions
Solutions 

Creating DLLs for WinRunner 
"DLLs Demystified" 
(Mercury Interactive's Worldwide Users Conference 2000)

Determine a character from its ascii code.

 

In WinRunner, it's easy to determine the ascii code from a character:

## Determine the ascii code of a character.
asc_code = ascii( "A" );   # asc_code = 65


The opposite action is also fairly easy, although the solution is buried in the sprintf() statement. Using the format string "%c" will convert the numeric value to the character. (Easy for those of us who are comfortable using C, but for others....)

## Determine the character from its ascii code.
out_char = sprintf( "%c", ascii_code );   # out_char = "A"


Instead of trying to remember arcane format strings, use one of these versions of the function AsciiToChar(). (Define it in a compiled module, of course.)

The first version of the function provides protection against nonprintable characters as input. The second allows nonprintable and extended characters, with an optional switch. If you don't want the protection at all, just remove the if statement and its dependent return "" statement from the first version:

if( ascii_code < 32 || ascii_code > 127 )
return "";

The code for both versions is in a text file to avoid the format mangling that browsers tend to do to normal pages. View AsciiToChar.txt.

 



Top of  This Page | R. E. Cook Home Page

Copyright R. E. Cook Consulting, 2000 - 2011.
All rights reserved.

The site is designed to look best when viewed with Internet Explorer 5.0 - 8.0. Results with other browsers will probably deviate from what is intended.

NOTE: This website refers to registered trademarks and service marks that are owned by other companies, including Mercury Interactive, WinRunner, TestDirector, TSL, Microsoft, Windows.