Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

capital letters to tiny

ekeom
Anfänger
1.306Aufrufe
Hello,

How can I convert a capital letter string to tiny string, in fortran of course.

Best regards,

Didace
0 Kudos
3 Antworten
TimP
Geehrter Beitragender III
1.306Aufrufe
If you are writing it out yourself, you would use CHAR and ICHAR, or ACHAR and IACHAR, according to your requirements. Working one character at a time, you would use something like

character upchar, lowchar

lowchar= CHAR(ICHAR('a')-ICHAR('A') + ICHAR(upchar))

For a general string, of course, you would check upchar and convert only when upchar >= 'A' .and. upchar ='Z'.
ekeom
Anfänger
1.306Aufrufe
Tank you very much

Didace
Hirchert__Kurt_W
Neuer Beitragender II
1.306Aufrufe
I know of no Fortran system where this code will not work, but strictly speaking, the standard does not guarantee that it will work. If that bothers you, change ICHAR to IACHAR and CHAR to ACHAR to get code that _does_ have such a guarantee. Of course, given that ACHAR and IACHAR were not a part of the FORTRAN 77 standard, using them could affect your theoretical portability in a slightly different way.

I _do_ know of systems where the suggested test for capital letters will give the wrong answer. In particular, systems that use EBCDIC rather than ASCII as the native character set have characters other than letters between 'A' and 'Z'. If you feel like indulging your portability paranoia, test for LLE('A',upchar) and LLE(upchar,'Z'). This does the order test in ASCII even if the native character set is something else, so you are guaranteed that there are no nonletters mixed in among the letters. LLE _was_ available in FORTRAN 77.

Of course, all the above is for the 26 letters in the English alphabet. Many western European languages have letters beyond those 26; many other languages have entirely different alphabets. In those other alphabets, converting upper case to lower case, if that concept makes any sense at all, becomes a significantly more difficult problem.
Antworten