Article View: borland.public.cppbuilder.nativeapi
Article #10859Re: Removing unregular characters for Win98 folder name...
From: fisher
Date: Thu, 11 Mar 2004 18:14
Date: Thu, 11 Mar 2004 18:14
46 lines
2476 bytes
2476 bytes
Consider using the STL algorithm remove function:
As taken from SGI documentation on STL:
www.sgi.com
Prototype:
template <class ForwardIterator, class T>
ForwardIterator remove(ForwardIterator first, ForwardIterator last,
const T& value);
Complexity:
Linear. Remove performs exactly last - first comparisons for equality.
Example:
vector<int> V;
V.push_back(3);
V.push_back(1);
V.push_back(4);
V.push_back(1);
V.push_back(5);
V.push_back(9);
copy(V.begin(), V.end(), ostream_iterator<int>(cout, " "));
// The output is "3 1 4 1 5 9".
vector<int>::iterator new_end = remove(V.begin(), V.end(), 1);
copy(V.begin(), new_end, ostream_iterator<int>(cout, " "));
// The output is "3 4 5 9".
Notes:
[1] The meaning of "removal" is somewhat subtle. Remove does not destroy any
iterators, and does not change the distance between first and last. (There's
no way that it could do anything of the sort.) So, for example, if V is a
vector, remove(V.begin(), V.end(), 0) does not change V.size(): V will
contain just as many elements as it did before. Remove returns an iterator
that points to the end of the resulting range after elements have been
removed from it; it follows that the elements after that iterator are of no
interest, and may be discarded. If you are removing elements from a
Sequence, you may simply erase them. That is, a reasonable way of removing
elements from a Sequence is S.erase(remove(S.begin(), S.end(), x), S.end()).
Technical Details
Message-ID:
<4050ab77@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.freenet.de!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4050a0e3@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,c7153abde107ab57 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-03-11 10:10:38 PST Reply-To: "fisher" <na> From: "fisher" <na> Newsgroups: borland.public.cppbuilder.nativeapi References: <4050a0e3@newsgroups.borland.com> Subject: Re: Removing unregular characters for Win98 folder name... Date: Thu, 11 Mar 2004 13:14:38 -0500 Lines: 49 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 157.232.193.169 Message-ID: <4050ab77@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1079028599 157.232.193.169 (11 Mar 2004 10:09:59 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.freenet.de!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail