Chapter 24. Strings

Table of Contents

24.. Motivation
24.. Defining String Variables
24.. String Constants
24.. Truncation and Padding
24.. Common String Operations
String length
24.. Strings as Subprogram Arguments
24.. Command-line Arguments
24.. Code Quality
24.. Performance
Code Examples
24.. Self-test


Most programs need to communicate with end users. To facilitate this, we have character sets such as ASCII, ISO-Latin1, and Unicode. A sequence of such characters is called a string.

All input from and output to a terminal is in the form of a strings, even if that input and output is numeric. When you type in the number 451.32 as input to a program, you are sending the program the characters '4', '5', '1', '.', '3', and '2'. The Fortran read subroutine then converts this string of characters to the appropriate binary format (usually two's complement or IEEE floating point) and stores it in some variable.

Some programs are meant to process character data, not numeric data. For example, a program to manipulate genetic data might use strings of 'a' for adenine, 'c' for cytosine, 'g' for guanine, 't' for thymine (and perhaps 'u' for uracil, which is almost identical to thymine).