Minimal yet powerful variable-length string type with modern Fortran features. This module implements a lightweight string derived type that behaves like a true variable-length character string while remaining fully compatible with intrinsic Fortran character operations.
Features:
allocatable character(:)=) between string and character(*)// (concatenation), == (equality), .contains. (membership)len, len_trim, trimwrite, print)The design is intentionally minimal — it provides only what's necessary for robust string handling in scientific and preprocessing applications, avoiding the bloat of larger string libraries while remaining fast and standards-compliant.
pure or elemental when possible for maximum performance and usability in array contexts.Data Types | |
| type | string |
| Represents text as a sequence of ASCII code units. The derived type wraps an allocatable character array. More... | |
| interface | len |
| Return the length of a string. More... | |
| interface | len_trim |
| Return the trimmed length of a string. More... | |
| interface | trim |
| Return the trimmed string. More... | |
| interface | operator(//) |
| Concatenation operator. More... | |
| interface | operator(.contains.) |
| Check whether a string belongs to a list or not. More... | |
| character(:) function, allocatable, public concat | ( | character(*), intent(in) | str1, |
| character(*), intent(in) | str2 ) |
Smart concatenation that removes continuation markers (&) and handles line-continuation rules.
| [in] | str1 | first line |
| [in] | str2 | second line |
Remarks
Definition at line 535 of file string.f90.
| character function, public head | ( | character(*), intent(in) | str | ) |
Returns the first non-blank character of a string.
| [in] | str | input string |
Remarks
Definition at line 502 of file string.f90.
| character(1) function, public previous | ( | character(*), intent(in) | line, |
| integer, intent(inout) | pos ) |
Returns the previous non-blank character before position pos (updates pos).
| [in] | line | input line |
| [in,out] | pos | current position (moved backward) |
Remarks
Definition at line 641 of file string.f90.
| logical function, public starts_with | ( | character(*), intent(in) | str, |
| character(*), intent(in) | arg1, | ||
| integer, intent(out), optional | idx ) |
Checks if a string starts with a given prefix Returns .true. if the string str (after trimming leading/trailing whitespace) begins exactly with the substring arg1. The function uses index() after trimming both strings with trim(adjustl()).
| [in] | str | The string to be tested |
| [in] | arg1 | The prefix to look for at the beginning of str |
| [out] | idx | (optional) If present, receives the starting position of arg1 in the trimmed string (will be 1 if the function returns .true., otherwise >1 or 0) |
.true. if str starts with arg1 (after trimming), .false. otherwiseNote
str and arg1 is ignoredarg1 will always return .true. (any string starts with empty string)Warning The returned index (when requested) is the position after trimming of the input string, not in the original untrimmed string.
Examples
Remarks
Definition at line 484 of file string.f90.
| character function, public tail | ( | character(*), intent(in) | str | ) |
Returns the last non-blank character of a string.
| [in] | str | input string |
Remarks
Definition at line 517 of file string.f90.
| pure character(len_trim(str)) function, public uppercase | ( | character(*), intent(in) | str | ) |
Convert string to upper case (respects contents of quotes).
| [in] | str | input string |
Examples
Remarks
Definition at line 582 of file string.f90.
| subroutine, public writechk | ( | integer, intent(in) | unit, |
| character(*), intent(in) | str ) |
Write a long line split into chunks of size CHKSIZE with continuation (&).
| [in] | unit | logical unit |
| [in] | str | string to write |
Remarks
Definition at line 618 of file string.f90.