Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Old 02-19-2007, 04:33 PM Removing whitespace
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
Does anyone know of any program that exisits that can remove whitespace at the end of files in a batch? It would be helpful to find such a program that can do this on a live web server.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-19-2007, 05:20 PM Re: Removing whitespace
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
I might have a possible solution using a Unix SED command to replace the newlines in files, but does anyone know how to write one?
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 02-20-2007, 12:17 AM Re: Removing whitespace
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
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.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 02-21-2007, 06:07 PM Re: Removing whitespace
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
Yes - I was hopeing there was another source for doing this instead of writing a script, but I finally got through it. Thanks.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Removing whitespace
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26123 seconds with 12 queries