ICHAR(3) - [CHARACTER:CONVERSION] Character-to-integer code conversion function
result = ichar(c [,kind])
elemental integer(kind=KIND) function ichar(c,KIND)character(len=1,kind=**),intent(in) :: c integer,intent(in),optional :: KIND
o C is a scalar character o KIND is a constant integer initialization expression indicating the kind parameter of the result. o The return value is of type integer and of kind KIND. If KIND is absent, the return value is of default integer kind.
ICHAR(3) returns the code for the character in the systems native character set. The correspondence between characters and their codes is not necessarily the same across different Fortran implementations. For example, a platform using EBCDIC would return different values than an ASCII platform.
See IACHAR(3) for specifically working with the ASCII character set.
o C : The input character to determine the decimal code of. The range of values capable of representation is processor-dependent. o KIND : indicates the kind parameter of the result. If KIND is absent, the return value is of default integer kind.
The code in the system default character set for the character being queried is returned.
The result is the position of C in the processor collating sequence associated with the kind type parameter of C.
it is nonnegative and less than n, where n is the number of characters in the collating sequence.
The kind type parameter of the result shall specify an integer kind that is capable of representing n.
For any characters C and D capable of representation in the processor, C <= D is true if and only if ICHAR (C) <= ICHAR (D) is true and C == D is true if and only if ICHAR (C) == ICHAR (D) is true.
Sample program:
program demo_ichar use,intrinsic :: iso_fortran_env, only : b=>int8 implicit none integer,parameter :: bytes=80 character :: string*(bytes),lets((bytes))*1 integer(kind=b) :: ilets(bytes) equivalence (string,lets) equivalence (string,ilets) write(*,*)ichar([a,z,A,Z]) string=Do unto others associate (a=>ichar(lets)) ilets=merge(a-32,a,a>=97.and.a<=122) ! uppercase write(*,*)string ilets=merge(a+32,a,a>=65.and.a<=90) ! lowercase write(*,*)string end associate end program demo_icharResults:
> 97 122 65 90 > DO UNTO OTHERS > do unto others
Fortran 95, with KIND argument -Fortran 2003
ACHAR(3), CHAR(3), IACHAR(3)
Functions that perform operations on character strings, return lengths of arguments, and search for certain arguments:
SCAN(3), VERIFY(3)
o ELEMENTAL: ADJUSTL(3), ADJUSTR(3), INDEX(3), Fortran intrinsic descriptions (license: MIT) @urbanjost
o NONELEMENTAL: LEN_TRIM(3), LEN(3), REPEAT(3), TRIM(3)
Nemo Release 3.1 | ichar (3fortran) | November 02, 2024 |