|
Yeah, it's easy, but what language / technology are you using?
If it's Unix, I'm guessing you're not a .net fan? Unless you run Project Mono? I don't use PHP, so I can't give you the actual code, but if you're talking whitespace in a text file, you can read the file into a string, and then use a trim function, or righttrim.
Otherwise, if they're going to be large enough that trying to read one into memory could be a bad thing, you can read in the file byte-by-byte ( ideally you'd stream it in chunks ) and look for the last occurance of a non-whitespace character. Something like:
for(int i = 0; i < data.Length; i+)
if(data[i] != ' ' && data[i] != '\n' && data[i] != '\t')
lastPosition = i;
And then truncate the file to this point.
|