CHAR(3) - [CHARACTER:CONVERSION] Generate a character from a code value
result = char(i [,kind])
elemental character(kind=KIND) function char(i,KIND)integer(kind=**),intent(in) :: i integer(kind=**),intent(in),optional :: KIND
o a kind designated as ** may be any supported kind for the type o I is an integer of any kind o KIND is an integer initialization expression indicating the kind parameter of the result. o The returned value is a character with the kind specified by KIND or if KIND is not present, the default character kind.
Generates a character value given a numeric code representing the position I in the collating sequence associated with the specified kind KIND.
Note that ACHAR(3) is a similar function specifically for ASCII characters that is preferred when only ASCII is being processed, which is equivalent to CHAR(I,KIND=SELECTED_CHAR_KIND("ASCII") )
The ICHAR(3) function is the reverse of CHAR(3), converting characters to their collating sequence value.
o I : a value in the range 0 <= I <= N-1, where N is the number of characters in the collating sequence associated with the specified kind type parameter. : For ASCII, N is 127. The default character set may or may not allow higher values. o KIND : A constant integer initialization expression indicating the kind parameter of the result. If not present, the default kind is assumed.
The return value is a single character of the specified kind, determined by the position of I in the collating sequence associated with the specified KIND.
Sample program:
program demo_char implicit none integer, parameter :: ascii = selected_char_kind ("ascii") character(len=1, kind=ascii ) :: c, esc integer :: i ! basic i=74 c=char(i) write(*,*)ASCII character ,i,is ,c write(*,(*(g0)))Uppercase ASCII: ,(char(i),i=65,90) write(*,(*(g0)))lowercase ASCII: ,(char(i),i=97,122) esc=char(27) write(*,(*(g0)))Elemental: ,char([65,97,90,122]) ! print *, a selection of ASCII characters (shows hex if not printable) do i=0,127,10 c = char(i,kind=ascii) select case(i) case(32:126) write(*,(i3,1x,a))i,c case(0:31,127) ! print hexadecimal value for unprintable characters write(*,(i3,1x,z2.2))i,c case default write(*,(i3,1x,a,1x,a))i,c,non-standard ASCII end select enddoResults:end program demo_char
> ASCII character 74 is J > Uppercase ASCII: ABCDEFGHIJKLMNOPQRSTUVWXYZ > lowercase ASCII: abcdefghijklmnopqrstuvwxyz > Elemental: AaZz > a selection of ASCII characters (shows hex if not printable) > 0 00 > 10 0A > 20 14 > 30 1E > 40 ( > 50 2 > 60 < > 70 F > 80 P > 90 Z > 100 d > 110 n > 120 x
FORTRAN 77
ACHAR(3), IACHAR(3), ICHAR(3)
Functions that perform operations on character strings, return lengths of arguments, and search for certain arguments:
Fortran intrinsic descriptions (license: MIT) @urbanjost
o ELEMENTAL: ADJUSTL(3), ADJUSTR(3), INDEX(3), SCAN(3), VERIFY(3) o NONELEMENTAL: LEN_TRIM(3), LEN(3), REPEAT(3), TRIM(3)
Nemo Release 3.1 | char (3fortran) | November 02, 2024 |