ASCII

The stdlib_ascii module

Introduction

The stdlib_ascii module provides procedures for handling and manipulating intrinsic character variables and constants.

Constants provided by stdlib_ascii

Specification of the stdlib_ascii procedures

to_lower

Status

Experimental

Description

Converts input character variable to all lowercase.

Syntax

res = to_lower (string)

Class

Pure function.

Argument

string: shall be an intrinsic character type. It is an intent(in) argument.

Result value

The result is an intrinsic character type of the same length as string.

Example

program demo_to_lower
    use stdlib_ascii, only : to_lower
    implicit none
    print'(a)', to_lower("HELLo!") ! returns "hello!"
 end program demo_to_lower

to_upper

Status

Experimental

Description

Converts input character variable to all uppercase.

Syntax

res = to_upper (string)

Class

Pure function.

Argument

string: shall be an intrinsic character type. It is an intent(in) argument.

Result value

The result is an intrinsic character type of the same length as string.

Example

program demo_to_upper
    use stdlib_ascii, only : to_upper
    implicit none
    print'(a)', to_upper("hello!") ! returns "HELLO!"
 end program demo_to_upper

to_title

Status

Experimental

Description

Returns the titlecase version of the input character variable.
Title case: First character of every word in the sentence is converted to uppercase and the rest of the characters are converted to lowercase.
A word is a contiguous sequence of character(s) which consists of alphabetical character(s) and numeral(s) only and doesn't exclude any alphabetical character or numeral present next to either of its 2 ends.

Syntax

res = to_title (string)

Class

Pure function.

Argument

string: shall be an intrinsic character type. It is an intent(in) argument.

Result value

The result is an intrinsic character type of the same length as string.

Example

program demo_to_title
    use stdlib_ascii, only : to_title
    implicit none
    print*, to_title("hello there!") ! returns "Hello There!"
    print*, to_title("'enquoted'") ! returns "'Enquoted'"
    print*, to_title("1st")  ! returns "1st"
 end program demo_to_title

to_sentence

Status

Experimental

Description

Returns the sentencecase version of the input character variable.
The first alphabetical character of the sequence is transformed to uppercase unless it follows a numeral. The rest of the characters in the sequence are transformed to lowercase.

Syntax

res = to_sentence (string)

Class

Pure function.

Argument

string: shall be an intrinsic character type. It is an intent(in) argument.

Result value

The result is an intrinsic character type of the same length as string.

Example

program demo_to_sentence
    use stdlib_ascii, only : to_sentence
    implicit none
    print*, to_sentence("hello!") ! returns "Hello!"
    print*, to_sentence("'enquoted'") ! returns "'Enquoted'"
    print*, to_sentence("1st")  ! returns "1st"
 end program demo_to_sentence

reverse

Status

Experimental

Description

Reverses the order of all characters in the input character type.

Syntax

res = reverse (string)

Class

Pure function.

Argument

string: shall be an intrinsic character type. It is an intent(in) argument.

Result value

The result is an intrinsic character type of the same length as string.

Example

program demo_reverse
    use stdlib_ascii, only : reverse
    implicit none
    print'(a)', reverse("Hello, World!") ! returns "!dlroW ,olleH"
end program demo_reverse

to_string

Status

Experimental

Description

Create a character string representing the value of the provided variable.

Syntax

res = to_string (string)

Class

Pure function.

Argument

val: shall be an intrinsic integer or logical type. It is an intent(in) argument.

Result value

The result is an intrinsic character type.

Example

program demo_string_value
    use stdlib_ascii, only : to_string
    implicit none
    print'(a)', to_string(-3) ! returns "-3"
    print'(a)', to_string(.true.) ! returns "T"
    print'(a)', to_string(42) ! returns "42"
end program demo_string_value