NuMFor 9f2ab49 (2024-04-08)
Numerical (Modern) Fortran. Library for Simple Numerical computing
strings Module Reference

This module defines functions to manipulate strings of characters. Description. More...

Data Types

interface  str
 str() converts a number (integer or real) to a string More...
 

Functions/Subroutines

pure character(len=:) function, allocatable, public upper (s)
 Returns a copy of the string converted to uppercase.
 
pure character(len=:) function, allocatable, public lower (s)
 Returns a copy of the string converted to lowercase.
 
pure character(len=:) function, allocatable, public swapcase (s)
 Return str with case of letters swapped.
 
pure character(len=:) function, allocatable, public reverse (s)
 Reverse a string.
 
pure logical function, public endswith (s, suffix)
 Return True if S starts with the specified prefix, False otherwise.
 
pure logical function, public startswith (s, prefix)
 Return True if S starts with the specified prefix, False otherwise.
 
pure character(len=:) function, allocatable, public lstrip (s, chars)
 This function returns a copy of the string with leading chars removed.
 
pure character(len=:) function, allocatable, public rstrip (s, chars)
 This function returns a copy of the string with trailing chars removed.
 
pure character(len=:) function, allocatable, public strip (s, chars)
 This function returns a copy of the string with leading and trailing chars removed.
 
pure integer function count_sub (s, sub, start, end)
 Return the number of occurrences of substring sub in string S[start:end].
 
pure logical function, public issub (s, sub)
 Returns .True. if sub is present in S, .False. otherwise.
 
pure character(len=:) function, allocatable, public rjust (s, width, fillchar)
 Returns a right-justified string of length width.
 
pure character(len=:) function, allocatable, public ljust (s, width, fillchar)
 Returns a left-justified string of length width.
 
pure character(len=:) function, allocatable, public zfill (s, width)
 Pad a string with zeroes ("0") to specified width. If width is <= input string width, then the original string is returned.
 
character(len=:) function, allocatable, public center (s, width, fillchar)
 Center a string to a specified width. The default character to fill in the centered string is a blank character.
 
integer function, public find (s, sub, start, end)
 Return the lowest index in S where substring sub is found.
 
character(len=:) function, allocatable, public replace (s, old, new, count)
 Return a copy with all occurrences of substring old replaced by new.
 
integer function, public str2i (s_in)
 
character(len=:) function, allocatable z2str (zin)
 z2str gives a string representation of a complex number
 
function zarr2str (vec)
 
function dparr2str (vec)
 
function rarr2str (vec)
 
function iarr2str (vec)
 
character(len=:) function, allocatable dparr2d2str (vec)
 
character(len=:) function, allocatable rarr2d2str (vec)
 
character(len=:) function, allocatable iarr2d2str (vec)
 
character(len=:) function, allocatable zarr2d2str (vec)
 

Detailed Description

This module defines functions to manipulate strings of characters. Description.

Function/Subroutine Documentation

◆ center()

character(len=:) function, allocatable, public center ( character(len=*), intent(in) s,
integer, intent(in) width,
character(len=1), intent(in), optional fillchar )

Center a string to a specified width. The default character to fill in the centered string is a blank character.

Parameters
[in]sOriginal string
[in]widthTotal width of centered string
[in]fillcharPadding character (default to space)
Returns
A centered string of length width.

◆ count_sub()

pure integer function count_sub ( character(len=*), intent(in) s,
character(len=*), intent(in) sub,
integer, intent(in), optional start,
integer, intent(in), optional end )

Return the number of occurrences of substring sub in string S[start:end].

Parameters
[in]sOriginal string
[in]subsubstring to count
[in]startinitial position to consider
[in]endfinal position to consider
Returns
Number of occurrences of sub in S

◆ dparr2d2str()

character(len=:) function, allocatable dparr2d2str ( real(dp), dimension(:, :), intent(in) vec)
Parameters
[in]vecVector of numbers to convert
Returns
String created

◆ dparr2str()

function dparr2str ( real(dp), dimension(:), intent(in) vec)
Parameters
[in]vecVector to convert

◆ endswith()

pure logical function, public endswith ( character(len=*), intent(in) s,
character(len=*), intent(in) suffix )

Return True if S starts with the specified prefix, False otherwise.

Note
that differs from python method in that does not accept a tuple
Parameters
[in]sOriginal string
[in]suffixsubstring to test
Returns
.True. if S ends with sub.

◆ find()

integer function, public find ( character(len=*), intent(in) s,
character(len=*), intent(in) sub,
integer, intent(in), optional start,
integer, intent(in), optional end )

Return the lowest index in S where substring sub is found.

Returns
position where found
Parameters
[in]soriginal string
[in]subsubstring to find
[in]startinitial position to search
[in]endfinal position to search

Referenced by str::dp2str(), and str::r2str().

Here is the caller graph for this function:

◆ iarr2d2str()

character(len=:) function, allocatable iarr2d2str ( integer, dimension(:, :), intent(in) vec)
Returns
String created

◆ iarr2str()

function iarr2str ( integer, dimension(:), intent(in) vec)
Parameters
[in]vecVector to convert

◆ issub()

pure logical function, public issub ( character(len=*), intent(in) s,
character(len=*), intent(in) sub )

Returns .True. if sub is present in S, .False. otherwise.

Parameters
[in]sOriginal string
[in]subsubstring to find
Returns
True if sub is present in S

◆ ljust()

pure character(len=:) function, allocatable, public ljust ( character(len=*), intent(in) s,
integer, intent(in) width,
character(len=1), intent(in), optional fillchar )

Returns a left-justified string of length width.

Note
The string is never truncated
Parameters
[in]sOriginal string
[in]widthwidth of padded string
[in]fillcharChar used for filling
Returns
0-padded string

◆ lower()

pure character(len=:) function, allocatable, public lower ( character(len=*), intent(in) s)

Returns a copy of the string converted to lowercase.

Parameters
[in]sOriginal string
Returns
String converted to uppercase

Referenced by str::dp2str(), and str::r2str().

Here is the caller graph for this function:

◆ lstrip()

pure character(len=:) function, allocatable, public lstrip ( character(len=*), intent(in) s,
character(len=*), intent(in), optional chars )

This function returns a copy of the string with leading chars removed.

If chars is not present all blank: spaces (achar(32)) and tabs (achar(9)) are removed.

Note
that when used with no chars argument differs from intrinsic trim in that it will also strip "tab" characters
Parameters
[in]sOriginal string
[in]charschars to remove from S
Returns
String with chars removed

Referenced by str::dp2str(), str::r2str(), and strip().

Here is the caller graph for this function:

◆ rarr2d2str()

character(len=:) function, allocatable rarr2d2str ( real(sp), dimension(:, :), intent(in) vec)
Returns
String created

◆ rarr2str()

function rarr2str ( real(sp), dimension(:), intent(in) vec)
Parameters
[in]vecVector to convert

◆ replace()

character(len=:) function, allocatable, public replace ( character(len=*), intent(in) s,
character(len=*), intent(in) old,
character(len=*), intent(in) new,
integer, intent(in), optional count )

Return a copy with all occurrences of substring old replaced by new.

Parameters
[in]soriginal string
[in]oldsubstring to replace
[in]newsubstring to substitute from old
[in]countMaximum number of occurrences to replace
Returns
New string created

◆ reverse()

pure character(len=:) function, allocatable, public reverse ( character(len=*), intent(in) s)

Reverse a string.

Parameters
[in]sOriginal string
Returns
Reversed string

◆ rjust()

pure character(len=:) function, allocatable, public rjust ( character(len=*), intent(in) s,
integer, intent(in) width,
character(len=1), intent(in), optional fillchar )

Returns a right-justified string of length width.

Note
The string is never truncated
Parameters
[in]sOriginal string
[in]widthwidth of padded string
[in]fillcharChar used for filling
Returns
0-padded string

◆ rstrip()

pure character(len=:) function, allocatable, public rstrip ( character(len=*), intent(in) s,
character(len=*), intent(in), optional chars )

This function returns a copy of the string with trailing chars removed.

If chars is not present all blank: spaces (achar(32)) and tabs (achar(9)) are removed.

Note
that when used with no chars argument differs from intrinsic trim in that it will also strip "tab" characters
Parameters
[in]sOriginal string
[in]charschars to remove from S
Returns
String with chars removed

Referenced by str::dp2str(), str::r2str(), and strip().

Here is the caller graph for this function:

◆ startswith()

pure logical function, public startswith ( character(len=*), intent(in) s,
character(len=*), intent(in) prefix )

Return True if S starts with the specified prefix, False otherwise.

Note
that differs from python method in that does not accept a tuple as prefix
Parameters
[in]sOriginal string
[in]prefixsubstring to test
Returns
True if S starts with prefix

Referenced by zfill().

Here is the caller graph for this function:

◆ str2i()

integer function, public str2i ( character(len=:), intent(in), allocatable s_in)
Returns
Integer to convert
Parameters
[in]s_inString converted

◆ strip()

pure character(len=:) function, allocatable, public strip ( character(len=*), intent(in) s,
character(len=*), intent(in), optional chars )

This function returns a copy of the string with leading and trailing chars removed.

If chars is not present all blank: spaces (achar(32)) and tabs (achar(9)) are removed.

Note
that when used with no chars argument differs from intrinsic trim in that it will also strip "tab" characters
Parameters
[in]sOriginal string
[in]charschars to remove from S
Returns
String with chars removed

References lstrip(), and rstrip().

Referenced by str::dp2str(), str::i2str(), and str::r2str().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ swapcase()

pure character(len=:) function, allocatable, public swapcase ( character(len=*), intent(in) s)

Return str with case of letters swapped.

Parameters
[in]sOriginal string
Returns
String with cases swapped

◆ upper()

pure character(len=:) function, allocatable, public upper ( character(len=*), intent(in) s)

Returns a copy of the string converted to uppercase.

Parameters
[in]sOriginal string
Returns
String converted to uppercase

◆ z2str()

character(len=:) function, allocatable z2str ( complex(dp), intent(in) zin)

z2str gives a string representation of a complex number

Returns
String representation

◆ zarr2d2str()

character(len=:) function, allocatable zarr2d2str ( complex(dp), dimension(:, :), intent(in) vec)
Returns
String created

◆ zarr2str()

function zarr2str ( complex(dp), dimension(:), intent(in) vec)
Parameters
[in]vecVector to convert

◆ zfill()

pure character(len=:) function, allocatable, public zfill ( character(len=*), intent(in) s,
integer, intent(in) width )

Pad a string with zeroes ("0") to specified width. If width is <= input string width, then the original string is returned.

Note
The string is never truncated
Parameters
[in]sOriginal string
[in]widthwidth of padded string
Returns
0-padded string

References startswith().

Here is the call graph for this function: