splitstr Interface

public interface splitstr

Splits a string and returns the portion selected by the user.

Syntax

 t = splitstr(str, fieldNumber, delimiter, rev, mergedelim)

Where:

  • str: String that the user whants to split.
  • fieldNumber: Integer indicating which of the divisions to return.
  • delimiter: String that the user wants to use as a delimiter for splitting. Optional parameter. Default is Space.
  • rev: If true start spliting by the end of the string. Optional parameter. Default is False.
  • mergedelim: If true, contiguous delimiters in the string are merged before splitting. Optional parameter. Default is False.

It returns a string with the selected part of str. If the fieldNumber does not exists or if the delimiter does not exists it returns an empty string.

Example

The following program extracts some portions of a text:

 PROGRAM splitstrExample
    USE FU_Strings, ONLY: splitstr
    IMPLICIT NONE
    CHARACTER(LEN=:), ALLOCATABLE :: text
    CHARACTER(LEN=:), ALLOCATABLE :: portion
    text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, &
       &sed do eiusmod tempor incididunt ut labore et dolore magna al&
       &iqua. Ut enim ad minim veniam, quis nostrud exercitation ulla&
       &mco laboris nisi ut aliquip ex ea commodo consequat. Duis aut&
       &e irure dolor in reprehenderit in voluptate velit esse cillum&
       & dolore eu fugiat nulla pariatur. Excepteur sint occaecat cup&
       &idatat non proident, sunt in culpa qui officia deserunt molli&
       &t anim id est laborum."
    portion = splitstr(text, 1)
    WRITE(*,*) portion
    portion = splitstr(text, 2, rev = .True.)
    WRITE(*,*) portion
    portion = splitstr(text, 6, delimiter = "l"
    WRITE(*,*) portion
    portion = splitstr(text, 7, delimiter = "l"
    WRITE(*,*) portion
    portion = splitstr(text, 7, delimiter = "l", mergedelim = .True.)  
    WRITE(*,*) portion
 END PROGRAM splitstrExample

Contents


Module Procedures

private pure function splitstr_i8(str, fieldNumber, delimiter, rev, mergedelim) result(res)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

String that the user wants to split.

integer(kind=i8), intent(in) :: fieldNumber

Integer indicating which of the divisions to return.

character(len=*), intent(in), optional :: delimiter

String that the users wants to use as a delimiter for splitting. Optional parameter. Default is Space.

logical, intent(in), optional :: rev

If true start spliting by the end of the string. Optional parameter. Default is False.

logical, intent(in), optional :: mergedelim

If true, contiguous delimiters in the string are merged before splitting. Optional parameter. Default is False.

Return Value character(len=:), ALLOCATABLE

A string with the selected part of str. If the fieldNumber does not exists or if the delimiter does not exists it returns an empty string.

private pure function splitstr_i16(str, fieldNumber, delimiter, rev, mergedelim) result(res)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

String that the user wants to split.

integer(kind=i16), intent(in) :: fieldNumber

Integer indicating which of the divisions to return.

character(len=*), intent(in), optional :: delimiter

String that the users wants to use as a delimiter for splitting. Optional parameter. Default is Space.

logical, intent(in), optional :: rev

If true start spliting by the end of the string. Optional parameter. Default is False.

logical, intent(in), optional :: mergedelim

If true, contiguous delimiters in the string are merged before splitting. Optional parameter. Default is False.

Return Value character(len=:), ALLOCATABLE

A string with the selected part of str. If the fieldNumber does not exists or if the delimiter does not exists it returns an empty string.

private pure function splitstr_i32(str, fieldNumber, delimiter, rev, mergedelim) result(res)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

String that the user wants to split.

integer(kind=i32), intent(in) :: fieldNumber

Integer indicating which of the divisions to return.

character(len=*), intent(in), optional :: delimiter

String that the users wants to use as a delimiter for splitting. Optional parameter. Default is Space.

logical, intent(in), optional :: rev

If true start spliting by the end of the string. Optional parameter. Default is False.

logical, intent(in), optional :: mergedelim

If true, contiguous delimiters in the string are merged before splitting. Optional parameter. Default is False.

Return Value character(len=:), ALLOCATABLE

A string with the selected part of str. If the fieldNumber does not exists or if the delimiter does not exists it returns an empty string.

private pure function splitstr_i64(str, fieldNumber, delimiter, rev, mergedelim) result(res)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

String that the user wants to split.

integer(kind=i64), intent(in) :: fieldNumber

Integer indicating which of the divisions to return.

character(len=*), intent(in), optional :: delimiter

String that the users wants to use as a delimiter for splitting. Optional parameter. Default is Space.

logical, intent(in), optional :: rev

If true start spliting by the end of the string. Optional parameter. Default is False.

logical, intent(in), optional :: mergedelim

If true, contiguous delimiters in the string are merged before splitting. Optional parameter. Default is False.

Return Value character(len=:), ALLOCATABLE

A string with the selected part of str. If the fieldNumber does not exists or if the delimiter does not exists it returns an empty string.