473,387 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

QUERY: strip trailing whitespace ... woes :S

I am wondering about what's the best and easiest way to strip trailing
whitespace from every single file in a folder, recursively.

I want to write a program/script so that you pass in a folder name and
it'll recursively go through all sub-folders and strips trailing
whitespace from every single file.

Trailing whitespace includes:

1. whitespaces at end of text lines, strip whitespace but retain text
2. whitespaces on empty lines, strip whitespace but leave the empty
line

Feb 20 '06 #1
1 2135
In message <11**********************@g14g2000cwa.googlegroups .com>,
KevinGPO <ke******@hotmail.com> writes
I am wondering about what's the best
Define "best". Fastest? Easiest to code?
and easiest
For the programmer or for the user?
way to strip trailing
whitespace from every single file in a folder, recursively.

I want to write a program/script so that you pass in a folder name and
it'll recursively go through all sub-folders and strips trailing
whitespace from every single file.
Standard C++ has no concept of "folder", "sub-folder" or even "every ...
file", so the solution is inevitably going to be platform-dependent and
off topic here. You might do better with a scripting language - for
example, perl has easy ways of applying operations to all matching
files.
Trailing whitespace includes:

1. whitespaces at end of text lines, strip whitespace but retain text
2. whitespaces on empty lines, strip whitespace but leave the empty
line


2 is just the special case of 1 when the text is of zero size. No need
to treat it specially.

std::string has lots of functions that might help - find_last_not_of,
for example.

--
Richard Herring
Feb 20 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: qwweeeit | last post by:
Hi all, I need to limit as much as possible the lenght of a source line, stripping white spaces (except indentation). For example: .. . max_move and AC_RowStack.acceptsCards ( self,...
17
by: Stanimir Stamenkov | last post by:
Is it possible to make two inline elements to appear adjacent stripping any white space appearing in between in the source? Example: <span class="adj">1</span> <span class="adj">2</span>...
5
by: Donald Canton | last post by:
What's the best way to remove trailing whitespace from a string? For example: "John C. Doe \t" would become "John C. Doe". Thanks.
5
by: dan.j.weber | last post by:
I'm using Python 2.3.5 and when I type the following in the interactive prompt I see that strip() is not working as advertised: >>>s = 'p p:p' >>>s.strip(' :') 'p p:p' Is this just me or...
5
by: micklee74 | last post by:
hi i have a file test.dat eg abcdefgh ijklmn <-----newline opqrs tuvwxyz
9
by: amattie | last post by:
Does anyone have any idea on how I can strip the extra whitespace in the XML that shows up when I receive a response from an ASP.NET 2.0 webservice? This has been discussed before, but no one has...
6
by: eight02645999 | last post by:
hi can someone explain strip() for these : 'example' when i did this: 'abcd,words.words'
7
by: Nick | last post by:
strip() isn't working as i expect, am i doing something wrong - Sample data in file in.txt: 'AF':'AFG':'004':'AFGHANISTAN':'Afghanistan' 'AL':'ALB':'008':'ALBANIA':'Albania'...
3
by: Colin J. Williams | last post by:
The Library Reference has strip( ) Return a copy of the string with the leading and trailing characters removed. The chars argument is a string specifying the set of characters to be removed....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.