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:
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.
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 object. More... | |
| interface | len_trim |
| Return the trimmed length of a string object. More... | |
| interface | trim |
| Remove trailing blanks from a string object. More... | |
| interface | operator(//) |
| Concatenate string and character expressions. More... | |
| interface | operator(.contains.) |
| Test whether a value is present in an array. More... | |
| interface | index |
| Locate the position of a substring. 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 |
Definition at line 762 of file string.f90.
| character function, public head | ( | character(*), intent(in) | str | ) |
Returns the first character of the trimmed string.
| [in] | str | input string |
Definition at line 731 of file string.f90.
| pure character(len_trim(str)) function, public lowercase | ( | character(*), intent(in) | str | ) |
Convert string to lower case (respects contents of quotes).
| [in] | str | input string |
Examples
Definition at line 851 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) |
Definition at line 908 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) |
Note
Warning The returned index (when requested) is the position after trimming of the input string, not in the original untrimmed string.
Examples
Definition at line 714 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 |
Definition at line 745 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
Definition at line 808 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 |
Definition at line 886 of file string.f90.