StringiFor
Strings Fortran Manipulator, with steroids
A string type for modern Fortran with the methods you miss from Python: split, join, replace, strip, slice, justify,
regular expressions, cast to and from numbers, read and write files, UTF-8 aware.
One type, one module, pure Fortran 2008.
A real session of the short program of the quick start below: every answer is one method of the string type.
🔤 A real string type One type holding a string of any length: arrays whose elements have different lengths, no trim() everywhere, no silent truncation. A first string |
🔗 A drop-in for character Assignment, //, the comparison operators and the intrinsics (trim, index, len_trim, repeat, ...) accept a string wherever a character goes. Strings and I/O |
✂️ Split, join, slice
split and partition into tokens (the empty CSV fields kept, if you want), join arrays back, slice with a stride, reverse characters or words, replace, strip, compact whitespace, squeeze repeats, transliterate sets of characters. String manipulation |
🔠 Case and layout
upper, lower, capitalize, camelCase, snake_case, Start Case; is_alpha, is_space, is_punct...; pad, center or justify to a width, expand tabs, wrap a paragraph in fully justified lines. Case conversion · Layout |
🔢 Numbers in, numbers out Assign any integer or real kind to a string, cast back with to_number, or with read_number and an error status; ask is_number, is_integer, is_real; hexadecimal representation with hex. Numbers |
📁 Files and paths Read a file into an array of lines or one string, write it back, read line by line; basedir, basename, extension, glob, wildcard match, temporary names. Files and paths |
⚖️ Comparisons that know more Longest common prefix of many strings, version numbers compared field by field, start_with, end_with, count. Comparing |
🎨 Encoding and colours Base64 encode and decode, escape and unescape, ANSI colours and styles for the terminal. Encoding · Colours |
🔍 Regular expressions
regex: search, match, groups by number or name, findall, split, sub with templates. The results of Python's re, in time linear in the text whatever the pattern: no catastrophic backtracking. Regular expressions |
🌐 UTF-8 and Unicode Methods that never cut a character in two; lengths and positions in characters or display columns with by=; check and repair UTF-8, C and XML escapes, Unicode whitespace, byte order marks, strsort. Unicode and UTF-8 |
⚡ Elemental by design Almost every method is pure or elemental: apply it to a whole array of strings in one statement, use it in pure procedures. Arrays of strings |
🧪 Tested by its own documentation Every method carries doctests in its source; every example of the documentation is a program compiled and run to produce the output shown. The examples |
🛠️ Standard Fortran, any build Fortran 2008, built with FoBiS, fpm, CMake or Make. Three small dependencies, fetched for you. Installation |
🔓 Multi-licensed GPL v3 for FOSS projects; BSD 2-Clause, BSD 3-Clause or MIT for closed source and commercial ones: pick the license that fits. Copyrights |
Full documentation · Tutorial · Cookbook · API reference
See it run
Real sessions of small programs, regenerated from their runs with the documentation: regular expressions, UTF-8, numbers.

Quick start
One type, string, and its methods. This is the whole program behind the session above: a select case on the
command, one method for each answer.
program sf
!< Quick start: a tiny command line tool, one StringiFor method for each command.
use stringifor
implicit none
type(string) :: command, text, other
type(string), allocatable :: lines(:)
integer :: l
command = argument(1)
text = argument(2)
select case(command%chars())
case('upper')
call show(text%upper()//'')
case('snake')
call show(text%snakecase()//'')
case('reverse')
call show(text%reverse_words()//'')
case('justify')
call text%justify(lines=lines, width=34)
do l = 1, size(lines)
call show('|'//lines(l)//'|')
enddo
case('newer')
other = argument(3)
call show(merge(text, other, text%compare_version(other) > 0)//'')
case('hex')
call show('0x'//text%hex())
case('number')
if (text%is_integer()) then
call show('an integer')
elseif (text%is_real()) then
call show('a real')
else
call show('not a number')
endif
endselect
contains
function argument(n) result(arg)
!< The n-th command line argument, as a string.
integer, intent(in) :: n
type(string) :: arg
character(:), allocatable :: buffer
integer :: length
call get_command_argument(n, length=length)
allocate(character(length) :: buffer)
call get_command_argument(n, value=buffer)
arg = buffer
endfunction argument
subroutine show(answer)
!< Print an answer, in colour.
character(*), intent(in) :: answer
type(string) :: coloured
coloured = answer
print '(A)', coloured%colorize(color_fg='cyan', style='bold_on')
endsubroutine show
endprogram sf
$ sf justify "StringiFor gives Fortran a string type with the methods you miss from Python."
|StringiFor gives Fortran a string|
|type with the methods you miss|
|from Python. |
Grows with your program
The same methods take you from a line of text to a report read from a file, cleaned, computed and laid out. This is
the output of the program built step by step in the
tutorial:

New to StringiFor? The tutorial builds a complete
program step by step; the cookbook has short recipes. Every
example is a compiled, runnable program in docs/examples/src, shown with its real output in the
documentation.
Install
One-line install
curl -fsSL https://github.com/szaghi/StringiFor/releases/latest/download/install.sh | bash
It installs the latest release into ~/.local with the build system you choose among those StringiFor ships
(--build fobis|fpm|cmake|make: a menu asks when you do not say), the compiler you name (--fc, --gnu, --intel),
one install per compiler (lib/stringifor/<compiler>-<version>/, include/stringifor/<compiler>-<version>/), and
makes it usable through pkg-config (pkg-config --cflags --libs stringifor, with
PKG_CONFIG_PATH=$HOME/.local/lib/pkgconfig). The release carries StringiFor's dependencies (BeFoR64, FACE, PENF), so
CMake and make need no network. Pass options after bash -s --, e.g. ... | bash -s -- --build cmake --prefix /opt/stringifor; --help lists them all, --uninstall removes the install. The installer is FoBiS's
(One-line installer).
FoBiS
Standalone — clone, fetch dependencies, and build:
git clone https://github.com/szaghi/StringiFor && cd StringiFor
fobis fetch # fetch PENF, FACE, BeFoR64
fobis build --mode stringifor-static-gnu # build static library
Or install directly in one command:
fobis install szaghi/StringiFor --mode stringifor-static-gnu
fobis install szaghi/StringiFor --mode stringifor-static-gnu --prefix /path/to/prefix
As a project dependency — declare StringiFor in your fobos and run fetch:
[dependencies]
deps_dir = src/third_party
StringiFor = https://github.com/szaghi/StringiFor
fobis fetch # fetch and build
fobis fetch --update # re-fetch and rebuild
fpm
Add to your fpm.toml:
[dependencies]
StringiFor = { git = "https://github.com/szaghi/StringiFor" }
fpm build
CMake
cmake -B build && cmake --build build
Makefile
make # static library
make TESTS=yes # build the tests suite
A Fortran 2008 compiler is required (see Installation).
Authors
Contributions are welcome — see the Contributing page.
Copyrights
This project is distributed under a multi-licensing system:
Anyone interested in using, developing, or contributing to this project is welcome — pick the license that best fits your needs.