Re: add a0 format to language to print trimmed character variables



Beliavsky wrote:

On Apr 29, 2:33 pm, Gary Scott <garylsc...@xxxxxxxxxxxxx> wrote:

Clive Page wrote:

In message <YrOdnaEiBo7Xk67bnZ2dnUVZ_tqnn...@xxxxxxxxxxx>, glen

Beliavsky wrote:

I wish there were an "a0" format for character variables, analogous to
i0 for integers, which would not print trailing spaces in character
variables.

I think that's an excellent suggestion - pity nobody thought of it in
time for F2003.

In order to be analogous to I0 though wouldn't it need to trim both
leading and trailing spaces? I don't think that would be the usual
desire though, but maybe you could specify '0a0' to trim leading and
trailing spaces.


ADJUSTL can be (and is) ELEMENTAL, unlike TRIM, because the LEN of the
RESULT is the same as that of the argument. Quoting the gfortran
documentation, "ADJUSTL(STR) will left adjust a string by removing
leading spaces. Spaces are inserted at the end of the string as
needed."

If a0 were in the language, one could just write

write (*,"(1000(1x,a0))") adjustl(char_vec)

to print an array of character variables with leading and trailing
spaces removed from character variables and one space inserted between
variables.

Certainly, but it is more verbose and potentially more inefficient. Specifying '0a0', the compiler could simply skip over leading blanks rather than physically moving the string left.

--

Gary Scott
mailto:garylscott@sbcglobal dot net

Fortran Library: http://www.fortranlib.com

Support the Original G95 Project: http://www.g95.org
-OR-
Support the GNU GFortran Project: http://gcc.gnu.org/fortran/index.html

If you want to do the impossible, don't hire an expert because he knows it can't be done.

-- Henry Ford
.



Relevant Pages

  • Re: add a0 format to language to print trimmed character variables
    ... which would not print trailing spaces in character ... In order to be analogous to I0 though wouldn't it need to trim both ...
    (comp.lang.fortran)
  • Re: MS Query Problem
    ... The field is a 20 character text string which represents an industry code, ... access & excel that are a problem. ... It would be a very unusual circumstance to keep trailing spaces. ...
    (microsoft.public.access.queries)
  • Re: How do you remove trailing spaces withour Trim function?
    ... Then type in the Charcharacter by: ... delimiter and see if that takes it out. ... How do you remove trailing spaces? ... I have tried using the Trim function to remove the trailing space, ...
    (microsoft.public.excel.misc)
  • Re: How do I get strings functionality with the StringBuilder?
    ... I use StreamReader to read but I need to process the content. ... need to find trailing spaces before a '>' character and remove them. ... Also within the string I should look for a character splitter ':' and remove ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Need pkey data type of 32 < x < 64 bits size.
    ... binary types. ... Character types are for words, and trailing spaces don't ... matter, case and accents may or may not matter, and bytes that represent ...
    (microsoft.public.sqlserver.programming)