<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[schnelles Regex-Cleaning]]></title><description><![CDATA[<p>Hallo</p>
<p>Ich suche nach dem schnellsten und elegantesten Weg einen String nach Sonderzeichen zu durchsuchen deren ASCII Wert unter 32 oder über 127 liegt.<br />
Aus ANSI C kenne ich es das man dazu eine kleine Funktion benutz, die jedes einzelne Zeichen durchläuft und prüft.<br />
Wie mache ich das in C++? Weiß das es in Boost so etwas gibt aber dazu habe ich gerade keine Bücher hier....<br />
Arbeite mit gcc 4.1.2 unter Debian Linux und suche nach einer kleine eleganten Lösung die möglichst schnell sein sollte.</p>
<p>Danke Magier</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/238835/schnelles-regex-cleaning</link><generator>RSS for Node</generator><lastBuildDate>Tue, 22 Sep 2026 16:26:40 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/238835.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 16 Apr 2009 12:49:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to schnelles Regex-Cleaning on Thu, 16 Apr 2009 12:49:59 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Ich suche nach dem schnellsten und elegantesten Weg einen String nach Sonderzeichen zu durchsuchen deren ASCII Wert unter 32 oder über 127 liegt.<br />
Aus ANSI C kenne ich es das man dazu eine kleine Funktion benutz, die jedes einzelne Zeichen durchläuft und prüft.<br />
Wie mache ich das in C++? Weiß das es in Boost so etwas gibt aber dazu habe ich gerade keine Bücher hier....<br />
Arbeite mit gcc 4.1.2 unter Debian Linux und suche nach einer kleine eleganten Lösung die möglichst schnell sein sollte.</p>
<p>Danke Magier</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1696670</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1696670</guid><dc:creator><![CDATA[magier-phil]]></dc:creator><pubDate>Thu, 16 Apr 2009 12:49:59 GMT</pubDate></item><item><title><![CDATA[Reply to schnelles Regex-Cleaning on Thu, 16 Apr 2009 12:53:46 GMT]]></title><description><![CDATA[<p>wie in C: eine schleife die alle buchstaben betrachtet. uU mit for_each statt einer schleife, aber warum sollte man es komplett anders lösen?</p>
<p>regex gehen natürlich in c++ genauso wie in c auch...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1696674</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1696674</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Thu, 16 Apr 2009 12:53:46 GMT</pubDate></item><item><title><![CDATA[Reply to schnelles Regex-Cleaning on Thu, 16 Apr 2009 13:02:28 GMT]]></title><description><![CDATA[<p>Jo, weiß das in C++ auch altes C funzt, dachte nur es gäbe etwas kürzeres... irgendwas schon vorgeschrieben... will nicht immer das Rad neu erfinden und meine eigenen Fehler suchen gehen.. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1696681</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1696681</guid><dc:creator><![CDATA[magier-phil]]></dc:creator><pubDate>Thu, 16 Apr 2009 13:02:28 GMT</pubDate></item><item><title><![CDATA[Reply to schnelles Regex-Cleaning on Thu, 16 Apr 2009 13:11:04 GMT]]></title><description><![CDATA[<p>Ich würds wahrscheinlich so in etwa anstellen:</p>
<pre><code class="language-cpp">#include &lt;cstdlib&gt;
using std::size_t;

template &lt;typename T&gt;
class CountEvil
{
public:
 typedef size_t size_type;
 typedef T value_type;

private:
 T lower;
 T upper;

 size_type count; 
public:
 CountEvil(T _lower, T _upper) : lower(_lower), upper(_upper), count(0) {}
 void operator () (T val) {if ((val &gt; upper) || (val &lt; lower)) ++count;}

 size_type Get() const {return count;}
};

#include &lt;algorithm&gt;
#include &lt;string&gt;
#include &lt;iostream&gt;

int main()
{
 std::string in;
 std::getline (std::cin, in);

 CountEvil &lt;std::string::value_type&gt; evilchars('a', 'Z');

 std::for_each(in.begin(), in.end(), evilchars);

 std::cout &lt;&lt; evilchars.Get() &lt;&lt; std::endl;
}
</code></pre>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1696686</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1696686</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Thu, 16 Apr 2009 13:11:04 GMT</pubDate></item><item><title><![CDATA[Reply to schnelles Regex-Cleaning on Thu, 16 Apr 2009 15:41:51 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/16305">@unskilled</a>,<br />
Dein Programm funktioniert nicht. An <code>std::for_each</code> wird eine Kopie übergeben <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Für Regex gibt es:<br />
<a href="http://www.boost.org/doc/libs/1_38_0/libs/regex/doc/html/index.html" rel="nofollow">http://www.boost.org/doc/libs/1_38_0/libs/regex/doc/html/index.html</a><br />
<a href="http://www.boost.org/doc/libs/1_38_0/doc/html/xpressive.html" rel="nofollow">http://www.boost.org/doc/libs/1_38_0/doc/html/xpressive.html</a></p>
<p>Aber hier empfiehlt es sich den genau gleichen Weg einzuschlagen, wie in C auch, dürfte wohl das schnellste und einfchste sein. Ich würde aber nicht <code>std::for_each</code> nehmen, sondern zum zählen z.B. <code>std::count_if</code> :<br />
<a href="http://www.cplusplus.com/reference/algorithm/count_if/" rel="nofollow">http://www.cplusplus.com/reference/algorithm/count_if/</a></p>
<p>Oder zum löschen, <code>std::remove_if</code> :<br />
<a href="http://www.cplusplus.com/reference/algorithm/remove_if/" rel="nofollow">http://www.cplusplus.com/reference/algorithm/remove_if/</a></p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1696752</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1696752</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Thu, 16 Apr 2009 15:41:51 GMT</pubDate></item><item><title><![CDATA[Reply to schnelles Regex-Cleaning on Thu, 16 Apr 2009 18:04:04 GMT]]></title><description><![CDATA[<p>Dravere schrieb:</p>
<blockquote>
<p>Oder zum löschen, <code>std::remove_if</code> :<br />
<a href="http://www.cplusplus.com/reference/algorithm/remove_if/" rel="nofollow">http://www.cplusplus.com/reference/algorithm/remove_if/</a></p>
</blockquote>
<p>ACK <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1696828</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1696828</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Thu, 16 Apr 2009 18:04:04 GMT</pubDate></item><item><title><![CDATA[Reply to schnelles Regex-Cleaning on Thu, 16 Apr 2009 18:08:48 GMT]]></title><description><![CDATA[<p>japp, count_if wär auch ne idee gewesen - verdammt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";D"
      alt="😉"
    /></p>
<p>btw:</p>
<pre><code class="language-cpp">int main()
{
 std::string in;
 std::getline (std::cin, in);

 const CountEvil &lt;std::string::value_type&gt; evilchars = std::for_each(in.begin(), in.end(), CountEvil &lt;std::string::value_type&gt; ('a', 'Z'));

 std::cout &lt;&lt; evilchars.Get() &lt;&lt; std::endl;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1696832</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1696832</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Thu, 16 Apr 2009 18:08:48 GMT</pubDate></item><item><title><![CDATA[Reply to schnelles Regex-Cleaning on Thu, 16 Apr 2009 18:19:58 GMT]]></title><description><![CDATA[<p>Bei <code>std::remove_if()</code> sollte man noch beachten, dass zuerst mal nichts gelöscht, sondern nur die Iterator-Range so umgeordnet wird, dass man einen zusammenhängenden Bereich am Schluss der Range mittels <code>erase()</code> wirklich löschen kann.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1696842</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1696842</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Thu, 16 Apr 2009 18:19:58 GMT</pubDate></item><item><title><![CDATA[Reply to schnelles Regex-Cleaning on Fri, 17 Apr 2009 15:59:04 GMT]]></title><description><![CDATA[<blockquote>
<p>Ich würds wahrscheinlich so in etwa anstellen:</p>
<p>#include &lt;cstdlib&gt;<br />
using std::size_t;</p>
<p>template &lt;typename T&gt;<br />
class CountEvil<br />
{<br />
public:<br />
typedef size_t size_type;<br />
typedef T value_type;</p>
<p>private:<br />
T lower;<br />
T upper;</p>
<p>size_type count;<br />
public:<br />
CountEvil(T _lower, T _upper) : lower(_lower), upper(_upper), count(0) {}<br />
void operator () (T val) {if ((val &gt; upper) || (val &lt; lower)) ++count;}</p>
<p>size_type Get() const {return count;}<br />
};</p>
<p>#include &lt;algorithm&gt;<br />
#include &lt;string&gt;<br />
#include &lt;iostream&gt;</p>
<p>int main()<br />
{<br />
std::string in;<br />
std::getline (std::cin, in);</p>
<p>CountEvil <a href="std::string::value_type" rel="nofollow">std::string::value_type</a> evilchars('a', 'Z');</p>
<p>std::for_each(in.begin(), in.end(), evilchars);</p>
<p>std::cout &lt;&lt; evilchars.Get() &lt;&lt; std::endl;<br />
}</p>
</blockquote>
<p>oder einfach</p>
<pre><code class="language-cpp">#include &lt;string&gt; 
#include &lt;iostream&gt; 
using namespace std;
int main() 
{ 
 std::string in; 
 std::getline (std::cin, in); 

 int count=0;
 for(string::iterator i=in.begin();i!=in.end();++i)
   if('a'&lt;=*i &amp;&amp; *i&lt;='z')
     ++count;
 cout &lt;&lt; count &lt;&lt; '\n'; 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1696844</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1696844</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Fri, 17 Apr 2009 15:59:04 GMT</pubDate></item><item><title><![CDATA[Reply to schnelles Regex-Cleaning on Fri, 17 Apr 2009 18:18:29 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<blockquote>
<p>Ich würds wahrscheinlich so in etwa anstellen:</p>
<p>#include &lt;cstdlib&gt;<br />
using std::size_t;</p>
<p>template &lt;typename T&gt;<br />
class CountEvil<br />
{<br />
public:<br />
typedef size_t size_type;<br />
typedef T value_type;</p>
<p>private:<br />
T lower;<br />
T upper;</p>
<p>size_type count;<br />
public:<br />
CountEvil(T _lower, T _upper) : lower(_lower), upper(_upper), count(0) {}<br />
void operator () (T val) {if ((val &gt; upper) || (val &lt; lower)) ++count;}</p>
<p>size_type Get() const {return count;}<br />
};</p>
<p>#include &lt;algorithm&gt;<br />
#include &lt;string&gt;<br />
#include &lt;iostream&gt;</p>
<p>int main()<br />
{<br />
std::string in;<br />
std::getline (std::cin, in);</p>
<p>CountEvil <a href="std::string::value_type" rel="nofollow">std::string::value_type</a> evilchars('a', 'Z');</p>
<p>std::for_each(in.begin(), in.end(), evilchars);</p>
<p>std::cout &lt;&lt; evilchars.Get() &lt;&lt; std::endl;<br />
}</p>
</blockquote>
<p>oder einfach</p>
<pre><code class="language-cpp">#include &lt;string&gt; 
#include &lt;iostream&gt; 
using namespace std;
int main() 
{ 
 std::string in; 
 std::getline (std::cin, in); 

 int count=0;
 for(string::iterator i=in.begin();i!=in.end();++i)
   if('a'&lt;=*i &amp;&amp; *i&lt;='z')
     ++count;
 cout &lt;&lt; count &lt;&lt; '\n'; 
}
</code></pre>
</blockquote>
<p>Gott! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1697434</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1697434</guid><dc:creator><![CDATA[nou]]></dc:creator><pubDate>Fri, 17 Apr 2009 18:18:29 GMT</pubDate></item><item><title><![CDATA[Reply to schnelles Regex-Cleaning on Fri, 17 Apr 2009 19:46:35 GMT]]></title><description><![CDATA[<p>Danke für alle eure Beiträge.. habe mir das hier zusammen geschrieben....</p>
<pre><code class="language-cpp">int F_Clean(string&amp; str_in)
{
    string str_temp;
    int int_now, int_count, int_re = 0;
    char chr_t;
    str_temp.clear();
    for (int_count = 0; int_count &lt; str_in.size() ; int_count++)
    {
        int_now = str_in[int_count];
        if ((int_now &gt; 31) &amp;&amp; (int_now &lt; 127))
        {
            chr_t = int_now;
            str_temp=str_temp + chr_t;
        }
        else
        {
            int_re++;
        }
    }
    str_in = str_temp;
    return int_re;
}
</code></pre>
<p>Nicht schön aber es funzt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f576.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--sunglasses"
      title=":sunglasses:"
      alt="🕶"
    /></p>
<p>BEDANKT!!!!!!!!!!!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1697517</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1697517</guid><dc:creator><![CDATA[magier-phil]]></dc:creator><pubDate>Fri, 17 Apr 2009 19:46:35 GMT</pubDate></item><item><title><![CDATA[Reply to schnelles Regex-Cleaning on Fri, 17 Apr 2009 20:08:09 GMT]]></title><description><![CDATA[<p>ein paar ideen, die mir da einfallen</p>
<pre><code class="language-cpp">int F_Clean(string&amp; str_in)
{
    string str_temp;
    for (string::itearator i=str_in.begin();i!=str.end();++i)
        if ((*i &gt; 31)/* &amp;&amp; (*i &lt; 127)*/)//signed char?!
            str_temp+=*i;
    swap(str_in,str_temp);
    return str_tmp.size()-str_in.size();
}
</code></pre>
<p>/*remove_if tönt sehr lecker, das würde ich aber vertahen bis lamda-dinge da sind. ;)*/</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1697529</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1697529</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Fri, 17 Apr 2009 20:08:09 GMT</pubDate></item></channel></rss>