The Queen's University of Belfast
Parallel Computer Centre

[Next] [Previous] [Top]

Character processing


Character Processing

Topics

Character type

Single characters and strings

Character is an intrinsic data type and may appear as:

Character Constants

Character (or literal) constants are defined by enclosing text within apostrophes.

"This ` is an apostrophe"

`This " is a double quote'

"This ` and "" are both types"

Character Variables

Specification

CHARACTER :: yesorno, sex='F'

CHARACTER(len=12) :: surname

CHARACTER(len=6) :: initials, title

title = `Prof.'

initials = `FJS'

surname = `Bloggs'

CHARACTER [(len= )] [,attr] :: name

Character manipulation

Concatenation

The only operator which may be applied to character strings in an expression is the conconcatenation operator //.

CHARACTER(len=6) :: surname

CHARACTER (len=24) :: name

surname = `Bloggs'

name = `Dr `//`Fred `//surname

Substrings

Substrings are sections of larger strings.

name( [start]:[stop] )

CHARACTER(len=7) :: lang=`Fortran'

lang(2:4) !ort

lang(6:6) !a

lang(:4) !Fort

lang(6:) !an

lang(:) !Fortran

lang(10:) !zero length string.

lang(5:10) !illegal 10>len

Intrinsic functions

CHARACTER(len=12) :: surname, firstname

INTEGER :: length, pos

...

length = LEN(surname) !len=12

firstname = `Walter`

pos = INDEX(firstname, `al`) !pos=2

firstname = `Fred`

pos = INDEX(firstname, `al`) !pos=0

length = LEN(TRIM(firstname)) !len=4


[Next] [Previous] [Top]
All documents are the responsibility of, and copyright, © their authors and do not represent the views of The Parallel Computer Centre, nor of The Queen's University of Belfast.
Maintained by Alan Rea, email A.Rea@qub.ac.uk
Generated with CERN WebMaker