in reply to How do I mark the end of a file?

The '^@'s you are seeing, presumable in some text editor, are most likely actually null bytes (ascii 0). In the same way that ascii 1 is sometimes represented as '^A' and ascii 3 as '^C'. That is to say, the editor or viewer you are using to inspect the file is performing a translation of 'invisible' ascii values below ascii 32 and representing them as a '^' followed by a visible character derived by adding 0x40 to the actual ascii value. Hence the two ascii chars ^@ are used to designate the original ascii 0 value.

Ascii 0 does not match the regex \s+, so your code is failing to remove them. If you substitute (\0+) for (\s+) in your regex, your code will probably do what you want.


Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.