- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tank you very much
Didace
Didace
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page