- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
Hello,
How can I convert a capital letter string to tiny string, in fortran of course.
Best regards,
Didace
How can I convert a capital letter string to tiny string, in fortran of course.
Best regards,
Didace
Link kopiert
3 Antworten
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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'.
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'.
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
Tank you very much
Didace
Didace
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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.
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
Themen-Optionen
- RSS-Feed abonnieren
- Thema als neu kennzeichnen
- Thema als gelesen kennzeichnen
- Diesen Thema für aktuellen Benutzer floaten
- Lesezeichen
- Abonnieren
- Drucker-Anzeigeseite