<?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[Prüfen, ob String nur Zahlen enthält]]></title><description><![CDATA[<p>Wie?</p>
<p>Sollte für char Arraies ebenso wie für strings anwendbar sein. Und sollte möglichst kurz und einfach sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/272496/prüfen-ob-string-nur-zahlen-enthält</link><generator>RSS for Node</generator><lastBuildDate>Fri, 28 Aug 2026 21:14:05 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/272496.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 18 Aug 2010 14:30:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Prüfen, ob String nur Zahlen enthält on Wed, 18 Aug 2010 14:49:14 GMT]]></title><description><![CDATA[<p>Wie?</p>
<p>Sollte für char Arraies ebenso wie für strings anwendbar sein. Und sollte möglichst kurz und einfach sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1941594</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1941594</guid><dc:creator><![CDATA[skullyan]]></dc:creator><pubDate>Wed, 18 Aug 2010 14:49:14 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfen, ob String nur Zahlen enthält on Wed, 18 Aug 2010 14:32:22 GMT]]></title><description><![CDATA[<p>Entweder Regex (tr1, boost), oder isdigit(..).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1941595</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1941595</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Wed, 18 Aug 2010 14:32:22 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfen, ob String nur Zahlen enthält on Wed, 18 Aug 2010 14:47:40 GMT]]></title><description><![CDATA[<p><code>isdigit()</code> prüft ja nur, ob das erste Zeichen eine Zahl ist. Ich brauche aber eine Funktion, die z.B. in diesen Fällen:</p>
<pre><code class="language-cpp">&quot;123Hallo&quot;

&quot;123 Hallo&quot;

&quot;Hallo123&quot;

&quot;H1allo&quot;
</code></pre>
<p><code>false</code> zurück gibt. Nur, wenn der eingegebene String nur aus Zahlen besteht, soll true ausgegeben werden:</p>
<pre><code class="language-cpp">&quot;2556&quot; == true
</code></pre>
<p>boost kenne ich noch nicht. Geht das damit?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1941603</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1941603</guid><dc:creator><![CDATA[skullyan]]></dc:creator><pubDate>Wed, 18 Aug 2010 14:47:40 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfen, ob String nur Zahlen enthält on Wed, 18 Aug 2010 14:47:36 GMT]]></title><description><![CDATA[<p>Für Strings (auch C-Strigs, also char*)<br />
Mit <a href="http://www.cplusplus.com/reference/clibrary/cctype/isdigit/" rel="nofollow">http://www.cplusplus.com/reference/clibrary/cctype/isdigit/</a> einen entspechenden Funktor (Funktionsobjekt) basteln und zusammen mit<br />
<a href="http://www.cplusplus.com/reference/algorithm/find_if/" rel="nofollow">http://www.cplusplus.com/reference/algorithm/find_if/</a> auf den String loslassen.</p>
<p>Für char:</p>
<pre><code class="language-cpp">char c = /*??*/;
//nicht portabel, da nicht garantiert, dass '0'-'9' in einer Reihe sind: 
return (c &gt;= '0' &amp;&amp; c &lt;= '9');
//portabel:

switch (c)
{
  case '0':
  case '1':
  case '2':
  case '3':
  case '4':
  case '5':
  case '6':
  case '7':
  case '8':
  case '9':
    return true;
  default:
    return false;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1941604</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1941604</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Wed, 18 Aug 2010 14:47:36 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfen, ob String nur Zahlen enthält on Wed, 18 Aug 2010 15:07:19 GMT]]></title><description><![CDATA[<p>pumuckl schrieb:</p>
<blockquote>
<pre><code class="language-cpp">//nicht portabel, da nicht garantiert, dass '0'-'9' in einer Reihe sind: 
return (c &gt;= '0' &amp;&amp; c &lt;= '9');
</code></pre>
</blockquote>
<p>Doch, ist garantiert.<br />
§2.3.3</p>
<blockquote>
<p>In both the source and execution basic character sets, the value of each character after 0 in the above list of decimal digits shall be one greater than the value of the previous.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1941616</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1941616</guid><dc:creator><![CDATA[jokester]]></dc:creator><pubDate>Wed, 18 Aug 2010 15:07:19 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfen, ob String nur Zahlen enthält on Wed, 18 Aug 2010 15:19:58 GMT]]></title><description><![CDATA[<p>pumuckl schrieb:</p>
<blockquote>
<p>Für Strings (auch C-Strigs, also char*)<br />
Mit <a href="http://www.cplusplus.com/reference/clibrary/cctype/isdigit/" rel="nofollow">http://www.cplusplus.com/reference/clibrary/cctype/isdigit/</a> einen entspechenden Funktor (Funktionsobjekt) basteln und zusammen mit<br />
<a href="http://www.cplusplus.com/reference/algorithm/find_if/" rel="nofollow">http://www.cplusplus.com/reference/algorithm/find_if/</a> auf den String loslassen.</p>
<p>Für char:</p>
<pre><code class="language-cpp">char c = /*??*/;
//nicht portabel, da nicht garantiert, dass '0'-'9' in einer Reihe sind: 
return (c &gt;= '0' &amp;&amp; c &lt;= '9');
//portabel:

switch (c)
{
  case '0':
  case '1':
  case '2':
  case '3':
  case '4':
  case '5':
  case '6':
  case '7':
  case '8':
  case '9':
    return true;
  default:
    return false;
}
</code></pre>
</blockquote>
<p>Super, das hat mir geholfen. Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1941623</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1941623</guid><dc:creator><![CDATA[skullyan]]></dc:creator><pubDate>Wed, 18 Aug 2010 15:19:58 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfen, ob String nur Zahlen enthält on Thu, 19 Aug 2010 11:40:30 GMT]]></title><description><![CDATA[<ul>
<li></li>
</ul>
]]></description><link>https://www.c-plusplus.net/forum/post/1941966</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1941966</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Thu, 19 Aug 2010 11:40:30 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfen, ob String nur Zahlen enthält on Thu, 19 Aug 2010 12:53:39 GMT]]></title><description><![CDATA[<p>regex wäre meine wahl gewesen. <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/1941996</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1941996</guid><dc:creator><![CDATA[PRIEST]]></dc:creator><pubDate>Thu, 19 Aug 2010 12:53:39 GMT</pubDate></item><item><title><![CDATA[Reply to Prüfen, ob String nur Zahlen enthält on Thu, 19 Aug 2010 13:03:59 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">std::string s = &quot;1234&quot;;
if(std::find_if(s.begin(), s.end(), !boost::bind(is_digit, boost::_1)) == s.end())
  return true;
else
  return false;
</code></pre>
<p>oder noch einfacher:<br />
return std::count_if(s.begin(), s.end(), isdigit) == s.size();</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1942001</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1942001</guid><dc:creator><![CDATA[Maxi]]></dc:creator><pubDate>Thu, 19 Aug 2010 13:03:59 GMT</pubDate></item></channel></rss>