Re: removing blanks from a file



Luka Djigas writes:

Greetings
English is not my mother language, so I'd like to apologize in
advance, if this sounds a little funny to you.
Since fortran programmers are running thin in my part of the world,
and since looks like there's a good deal of them here, I was wondering
if you could help me with a little problem I'm having (searched
google, found some half solutions but nothing concrete)

I have a file, which is the output of one of my programs. It's a
script file, and therefore it's not supposed to have blanks in it.
The file looks something like this
1.0, 1.0, 1.0
1.0, 1.0, 1.0
....
and it would be good if it looked like this
1.0,1.0,1.0
1.0,1.0,1.0
....

I tried something like this

CHARACTER(1) :: CH
INTEGER(4) :: IOEND=0
OPEN(1,FILE='FILE.TXT')
DO WHILE (IOEND/=-1)
READ(1, "(A1)", IOSTAT=IOEND, ADVANCE="NO")CH
IF CH=CHAR(49)
CH=CHAR(50)
WRITE(1, "(A1)", ADVANCE="NO")CH
END DO
CLOSE(1)
END

If you try it you will see that it has some drawbacks.

Please, if anyone has some ideas how to solve this problem, I'd be
very grateful, if he/she would share them.

Use two strings, each declared with a length corresponding to the longest
line you will encounter in the file. One string will be input, the other
output.

Use two character counters, one for the input string, one for the output
string. Use a DO loop to scan each character of the input string. If
that character is a non-blank, increment the character count for the
output string and copy that character to the output string. When done
scanning that line, write the output string to the output file, perhaps
using the TRIM function to eliminate trailing blanks.

.



Relevant Pages

  • RfD: Escaped Strings version 4
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... as an escape character for the entry of characters that cannot be ... \b BS (backspace, ASCII 8) ...
    (comp.lang.forth)
  • RfD: Escaped Strings version 4
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... as an escape character for the entry of characters that cannot be ... \b BS (backspace, ASCII 8) ...
    (comp.lang.forth)
  • Re: RfD: Escaped Strings
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... \b BS (backspace, ASCII 8) ... \ ** escapes to characters much as C does. ...
    (comp.lang.forth)
  • Re: A note on computing thugs and coding bums
    ... code is valid for any character set that is legal in C (which is a ... characters in the required source character set ... A String, in C Sharp or Java, can be redefined. ... allow programmers to handle some other data format, ...
    (comp.programming)
  • Re: input & output in assembly
    ... [As you've not specified OS or assembler, ... using individual character I/O and handling the rest yourself in your ... it finds in that string, ... ENTER key is pressed (maximum buffer size: ...
    (comp.lang.asm.x86)