110 likes | 265 Views
8. Characters and Strings. HTML version. Properties. Length of every character variable must be specified in advance: CHARACTER STR*10 CHARACTER STRA(20)*10. Assumed Length Declarations. Character constants : CHARACTER STR*(*) PARAMETER ( STR 'This is a string' )
E N D
8. Characters and Strings HTML version
Properties • Length of every character variable must be specified in advance: CHARACTER STR*10 CHARACTER STRA(20)*10
Assumed Length Declarations • Character constants : CHARACTER STR*(*) PARAMETER ( STR 'This is a string' ) • Dummy character variable : CHARACTER STR*(*) Length of STR = Length of actual argument. STR is a passed-length dummy argument.
Character assignments Padding and chopping are on the right. CHARACTER AUTHOR*30, SHORT*5, EXPAND*10 AUTHOR 'SHAKESPEARE, WILLIAM' SHORT AUTHOR EXPAND = SHORT SHORT is ‘SHAKE’ EXPAND is ‘SHAKE ’ ( with 5 trailing blanks )
Character Substrings CHARACTER METAL*10 METAL 'CADMIUM' METAL(2:4) gives ‘ADM’ METAL(:4) gives ‘CADM’ METAL(4:) gives ‘MIUM ’ ( with 3 trailing blanks ) METAL(8:8) gives ‘ ’ ( 1 blank )
Character Expressions Concatenation operator // : ‘CAD’ // ‘MIUM’ gives ‘CADMIUM’ CHARACTER METAL*10 METAL 'CADMIUM' METAL(4:) // METAL(2:4) gives ‘MIUM ADM’
Character Intrinsic Functions CHAR ICHAR INDEX LEN LGE LGT LLE LGT
CHAR(I) CHAR(48) gives 0 CHAR(65) gives A CHAR(97) gives a CHAR(1) gives Ctrl-A CHAR(27) gives ESC ICHAR(char) ICHAR(a) gives 106
INDEX( string, pattern ) gives position of the 1st occurrence of pattern in string. Result is 0 if pattern is not in string. LEN(string) gives the length of string.
Relational Expressions String1 .RO. String2 .EQ. .NE. .LT. .LE. .GT. .GE. ‘abc12’ .RO. ‘abcde’ ‘1’ .RO. ‘d’ LGE LGT LLE LGT LGE( ‘a’, ‘1’ ) is always equal to T.