noesc(3f) - [M_strings:NONALPHA] convert non-printable characters to a space (LICENSE:PD)
Synopsis
Description
Examples
Author
License
elemental function noesc(INSTR)
character(len=*),intent(in) :: INSTR character(len=len(instr)) :: noesc
Convert non-printable characters to a space.
Sample Program:
program demo_noesccharacters and their ADE (ASCII Decimal Equivalent)use M_strings, only : noesc implicit none character(len=128) :: ascii character(len=128) :: cleared integer :: i ! fill variable with base ASCII character set do i=1,128 ascii(i:i)=char(i-1) enddo cleared=noesc(ascii) write(*,*)characters and their ADE (ASCII Decimal Equivalent) call ade(ascii) write(*,*)Cleared of non-printable characters call ade(cleared) write(*,*)Cleared string: write(*,*)cleared contains subroutine ade(string) implicit none ! the string to print character(len=*),intent(in) :: string ! number of characters in string to print integer :: lgth ! counter used to step thru string integer :: i ! get trimmed length of input string lgth=len_trim(string(:len(string)))
! replace lower unprintable characters with spaces write(*,101)(merge(string(i:i), ,& & iachar(string(i:i)) >= 32 & & .and. & & iachar(string(i:i)) <= 126) & & ,i=1,lgth)
! print ADE value of character underneath it write(*,202) (iachar(string(i:i))/100, i=1,lgth) write(*,202)(mod( iachar(string(i:i)),100)/10,i=1,lgth) write(*,202)(mod((iachar(string(i:i))),10), i=1,lgth) ! format for printing string characters 101 format(*(a1:)) ! format for printing ADE values 202 format(*(i1:)) end subroutine ade end program demo_noesc
Expected output
The string is printed with the ADE value vertically beneath. The original string has all the ADEs from 000 to 127. After NOESC(3f) is called on the string all the "non-printable" characters are replaced with a space (ADE of 032).
> !"#$%&()*+,-./0123456789 :;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~ >0000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000001111111111111111111111111111 >00000000001111111111222222222233333333334444444444555555555566666666 667777777777888888888899999999990000000000111111111122222222 >012345678901234567890123456789012345678901234567890123456789012345678 90123456789012345678901234567890123456789012345678901234567Cleared of non-printable characters
> !"#$%&()*+,-./0123456789 :;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~ >0000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000111111111111111111111111111 >3333333333333333333333333333333333333333444444444455555555 556666666666777777777788888888889999999999000000000011111111112222222 >2222222222222222222222222222222223456789012345678901234567 890123456789012345678901234567890123456789012345678901234567890123456Cleared string:
> !"#$%&()*+,-./0123456789:;<=>?@ ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~
John S. Urban
Public Domain
Nemo Release 3.1 | noesc (3m_strings) | January 10, 2025 |