
-----------------------------------
Terror Byte
Sun Feb 19, 2006 11:59 am

Help with some Input/Output....
-----------------------------------
Okay I have to do several things with a couple of files.

I need to remove punctuation marks from a file.


const PUNC := ",.:;?!'"
var streamnumber : int
var streamnumber2 : int

open : streamnumber, "C:/Adeel/Turing/story.txt", get
open : streamnumber2, "C:/Adeel/Turing/no_punc.txt", put

loop
    exit when eof (streamnumber)
    get : streamnumber, letter
    for i : 1 .. 7
        if letter = PUNC (i) then
            letter := " "
        end if
    end for
    put : streamnumber2, letter ..
end loop

close : streamnumber
close : streamnumber2


Basically, I can remove the punctuation marks but they get replaced with a space... How do I get rid of the space? I've tried replacing it with "^H" which the Turing Help says acts like a backspace or something..

Can anyone help me out here?

-----------------------------------
Delos
Sun Feb 19, 2006 12:28 pm

Re: Help with some Input/Output....
-----------------------------------


        if letter = PUNC (i) then
            letter := " "
        end if



Look, a space!  I wonder what will happen if I...:lol:  By the way, your code won't work.  I mean, apart from having not declared 'letter'.  You're trying to get it to do something (check for punctuation), but instead you're setting up an equality test - not what you want to be doing.  Instead, look into the index() function.

-----------------------------------
Terror Byte
Sun Feb 19, 2006 12:31 pm


-----------------------------------
Oh I did declare letter as a char.. Just forgot to put it in the code.. It's part of a bigger exercize.

And it does seem to work. The file I get mirrors the original exactly except all the punctuation marks are gone and replaced with a space.

I just want to remove the punctuation marks and remove that space as well.

-----------------------------------
Cervantes
Sun Feb 19, 2006 12:38 pm


-----------------------------------
Sadly, you can't do something like this:

foo (12) := ""

Instead, you have to settle for this:

var foo := "Hello World! Ninja Pirate Wooble Foo."

% Find a punctuation mark at letter 12.
foo := foo (1 .. 11) + foo (13 .. *)

put foo

