Home | Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]

Case Folding


The and STRUPCASE functions are used to convert arguments to lowercase or uppercase. They have the form:

S = STRLOWCASE(String)

S = STRUPCASE(String)

where String is the string to be converted to lowercase or uppercase.

The following IDL statements generate a table of the contents of TREES showing each name in its actual case, lowercase and uppercase:

FOR I=0, 6 DO PRINT, trees[I], STRLOWCASE(trees[I]),$ 
STRUPCASE(trees[I]), FORMAT = '(A, T15, A, T30, A)' 

The resulting output from running this statement is as follows:

 
 
 
Beech
beech
BEECH
Birch
birch
BIRCH
Mahogany
mahogany
MAHOGANY
Maple
maple
MAPLE
Oak
oak
OAK
Pine
pine
PINE
Walnut
walnut
WALNUT

A common use for case folding occurs when writing IDL procedures that require input from the user. By folding the case of the response, it is possible to handle responses written in uppercase, lowercase, or mixed case. For example, the following IDL statements can be used to ask "yes or no" style questions:

;Create a string variable to hold the response. 
answer = '' 
 
;Ask the question. 
READ, 'Answer yes or no:  ', answer 
IF (STRUPCASE(answer) EQ 'YES') THEN $ 
   ;Compare the response to the expected answer. 
   PRINT,'YES' ELSE PRINT, 'NO' 

Home | Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]