Skip to content

Features ​

One type, one module ​

Everything is in the string type, exported by the stringifor module together with the numeric kinds and a few procedures:

fortran
use stringifor
type(string) :: s

s = 'Hello World'            ! assign
print '(A)', s%upper()//''   ! call a method, get a character with //

Feature map ​

AreaFeaturesWhere
The typea string of any length; arrays with elements of different lengths; assignment from characters, strings and numbers; // (a character) and .cat. (a string); ==, /=, <, <=, >=, >; defined I/OStrings and I/O
Intrinsicsadjustl, adjustr, count, index, len_trim, repeat, scan, trim, verify accept a stringStrings and I/O
Caseupper, lower, swapcase, capitalize, camelcase, snakecase, startcase; is_upper, is_lowerString Manipulation
Classesis_alpha, is_alnum, is_digit, is_xdigit, is_punct, is_spaceString Manipulation
Cleaningstrip (blanks or a set of characters), replace, unique, insert, escape, unescape, lstrip, rstrip, compact, squeeze, expand_tabs, transliterate, quote, unquoteString Manipulation
Tokenssplit (empty fields optionally kept), split_chunked, partition, join, strjoin (1D and 2D arrays)String Manipulation
Partsslice with a stride, reverse, reverse_words, start_with, end_with, count, index, scan, verify, search between tagsString Manipulation
Layoutfill, center, ljust, rjust, justify, len_last_wordString Manipulation
Comparingcommon_prefix, compare_versionString Manipulation
Numbersassignment from any integer and real kind; to_number, read_number with an error status; is_number, is_integer, is_real, is_digit; hexNumbers
Filesread_file, read_lines, read_line, write_file, write_lines, write_line, formatted or unformatted streamFiles and Paths
Pathsbasedir, basename, extension, glob, match of wildcard patterns, tempnameFiles and Paths
Encoding and coloursbase64 encode and decode; ANSI colorizeFiles and Paths

The methods summary lists every method with its arguments.

Design goals ​

GoalHow
Interchangeable with characteroverloaded assignment, //, comparisons and intrinsics: a string goes wherever a character does
Low memory consumptionone allocatable character is the only component: each element of an array is as long as its content
Safealmost every method is elemental or pure; the methods return new values and leave the string unchanged
Testedevery method carries doctests in its source; every example of these pages is compiled and run

Module architecture ​

Use only the stringifor module: it exports the type, the kinds (I1P, I2P, I4P, I8P, R4P, R8P, R16P), the character kind CK, the overloaded intrinsics, and the procedures read_file, read_lines, write_file, write_lines, glob and strjoin.

Compiler support ​

CompilerMinimum versionStatus
GNU gfortran≥ 9.2.0Full support
Intel ifort / ifx≥ 19.0.4Full support
NVIDIA nvfortran—Builds with the _NVF macro defined, which disables the I2P kind; not regularly tested
IBM XL—Not tested
NAG—Not tested

Any feature request is welcome: open an issue on GitHub.