- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Why is there a difference in returned length between:
and
and of course
same situation for
whereas
This seems to be a bit inconsistent.
I am just curious why it is implemented this way.
It appears that during the assignment:
Thanks,
Walter Kramer
Why is there a difference in returned length between:
character(28) :: str='I-have-blanks-behind-me ' string=trim(string) l=len(string) ! => l=28
and
l=len(trim(string)) ! => l=23
and of course
l=len_trim(string) ! => l=23
same situation for
string=trim(string) l=index(string," ") ! => l=24
whereas
l=index(trim(string)," ") ! => l=0
This seems to be a bit inconsistent.
I am just curious why it is implemented this way.
It appears that during the assignment:
string=trim(string)the string is padded with blanks. Is this Fortran standard?
Thanks,
Walter Kramer
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OK, I am sorry. I should have thought before acting.
I understand that assigning a trimmed string to a string with a (longer) fixed length requires some form of padding. Padding with blanks seems the logical choice.
Walter Kramer
I understand that assigning a trimmed string to a string with a (longer) fixed length requires some form of padding. Padding with blanks seems the logical choice.
Walter Kramer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, this is all standard. :-) The purpose of LEN is to return the total length of the string, including any trailing spaces. LEN_TRIM gives you the length without trailing spaces. As Fortran pads strings with spaces, it is nice to have both, one to tell you how much space you have available in the string variable, and another to tell you how much of that string variable is actually worth formatting.
The TRIM function returns a string of LEN_TRIM length of the original string, without the trailing spaces of course. But if you assign this back to the original string, the result will be the same as the TRIMmed string is space padded. So in your example, string=TRIM(string) does not change string, thus LEN(string) will not change either.
James
The TRIM function returns a string of LEN_TRIM length of the original string, without the trailing spaces of course. But if you assign this back to the original string, the result will be the same as the TRIMmed string is space padded. So in your example, string=TRIM(string) does not change string, thus LEN(string) will not change either.
James
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