<?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[In String]]></title><description><![CDATA[<p>Gibt's bei C++ einen Befehl mit dem ich herausfinden kann ob in einem String eine beliebe Zahl steckt? Oder zum Beispiel ein Unterstrich?</p>
<p>Allgemein, gibt es einen Befehl um herauszufinden ob eine bestimmte Zeichenkette in einem String steckt?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/163533/in-string</link><generator>RSS for Node</generator><lastBuildDate>Sun, 13 Sep 2026 12:31:55 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/163533.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 30 Oct 2006 16:05:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to In String on Mon, 30 Oct 2006 16:05:19 GMT]]></title><description><![CDATA[<p>Gibt's bei C++ einen Befehl mit dem ich herausfinden kann ob in einem String eine beliebe Zahl steckt? Oder zum Beispiel ein Unterstrich?</p>
<p>Allgemein, gibt es einen Befehl um herauszufinden ob eine bestimmte Zeichenkette in einem String steckt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1164652</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1164652</guid><dc:creator><![CDATA[becks21]]></dc:creator><pubDate>Mon, 30 Oct 2006 16:05:19 GMT</pubDate></item><item><title><![CDATA[Reply to In String on Mon, 30 Oct 2006 16:07:34 GMT]]></title><description><![CDATA[<p>string::find</p>
<p><a href="http://www.cppreference.com/cppstring/find.html" rel="nofollow">http://www.cppreference.com/cppstring/find.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1164656</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1164656</guid><dc:creator><![CDATA[GPC]]></dc:creator><pubDate>Mon, 30 Oct 2006 16:07:34 GMT</pubDate></item><item><title><![CDATA[Reply to In String on Mon, 30 Oct 2006 16:09:13 GMT]]></title><description><![CDATA[<p>ja gibts <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>
<pre><code class="language-cpp">// c++-string

std::string s = &quot;1q2343243542&quot;;
std::cout &lt;&lt; s.find(&quot;343&quot;) &lt;&lt; std::endl; // Ausgabe der position des ersten auftretens der zeichenikette &quot;343&quot; in s.

// wenn s.find(...) == s.npos, dann ist die zeichenikette nicht enthalten.

s.find(&quot;343&quot;, pos) sucht nach der zeichenkette, fängt aber erst ab dem pos. Zeichen in s damit an.

// c-string
mittels strstr(...)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1164660</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1164660</guid><dc:creator><![CDATA[Maxi]]></dc:creator><pubDate>Mon, 30 Oct 2006 16:09:13 GMT</pubDate></item><item><title><![CDATA[Reply to In String on Mon, 30 Oct 2006 16:12:02 GMT]]></title><description><![CDATA[<p>Weedjo versucht mit seinem beschränkten C++ Kenntnissen zu helfen:</p>
<p>Man könnte mit :</p>
<pre><code>Zahl = static_cast&lt;int&gt; (String123.find (&quot;5&quot;, 0) );
nach der Zahl 0 Suchen
bzw:
Unterstrich = static_cast&lt;int&gt; (String123.find (&quot;_&quot;, 0) );
</code></pre>
<p>Hoffe mal das geht so, bin mir halt nich sicher xD<br />
Denke man kann auch statt der &quot;5&quot; ne Variable einfügen, dann wird halt der wert der variable gesucht.</p>
<p>edit: too late <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>Edit2: Wenn du dann ne Abfrage machen willst, ob was gefunden wurde:</p>
<pre><code>if (Zahl != string::npos)
{
...
</code></pre>
<p>Denn wenn nichts gefunden wurde wird der wert &quot;npos&quot; übergeben</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1164661</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1164661</guid><dc:creator><![CDATA[Weedjo]]></dc:creator><pubDate>Mon, 30 Oct 2006 16:12:02 GMT</pubDate></item><item><title><![CDATA[Reply to In String on Mon, 30 Oct 2006 16:15:04 GMT]]></title><description><![CDATA[<p>Und wenn ich nur wissen will ob überhaupt eine Ziffer drin steckt? Muss ich dann nach 0123456789 suchen? Oder gibts da was?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1164671</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1164671</guid><dc:creator><![CDATA[becks21]]></dc:creator><pubDate>Mon, 30 Oct 2006 16:15:04 GMT</pubDate></item><item><title><![CDATA[Reply to In String on Mon, 30 Oct 2006 16:26:26 GMT]]></title><description><![CDATA[<p>Denke mal du musst alle Zahlen nehmen und die mit nem &quot;Oder&quot;-Operator verknüpfen, kenn keinen anderen weg<br />
also<br />
1 || 2 || 3... || 9 || 0</p>
<p>Edit : Habs grad ausprobiert, geht leider nicht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f622.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--crying_face"
      title=":'("
      alt="😢"
    /><br />
muss man so machen:</p>
<pre><code>Pos = static_cast&lt;int&gt; (string1.find_first_of (&quot;123456789_&quot;, 0) );
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1164677</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1164677</guid><dc:creator><![CDATA[Weedjo]]></dc:creator><pubDate>Mon, 30 Oct 2006 16:26:26 GMT</pubDate></item><item><title><![CDATA[Reply to In String on Mon, 30 Oct 2006 16:19:07 GMT]]></title><description><![CDATA[<p>find_first_of</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1164679</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1164679</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Mon, 30 Oct 2006 16:19:07 GMT</pubDate></item><item><title><![CDATA[Reply to In String on Mon, 30 Oct 2006 17:00:15 GMT]]></title><description><![CDATA[<p>Was bedeutet static_cast&lt;int&gt;?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1164716</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1164716</guid><dc:creator><![CDATA[becks21]]></dc:creator><pubDate>Mon, 30 Oct 2006 17:00:15 GMT</pubDate></item><item><title><![CDATA[Reply to In String on Mon, 30 Oct 2006 17:38:15 GMT]]></title><description><![CDATA[<p>Das ist ein cast, der hier dazu benutzt wird, nach int zu casten. Aber dieser cast ist völlig unnötig. Lass den weg.</p>
<p>Siehe auch hier: <a href="http://tutorial.schornboeck.net/casts.htm" rel="nofollow">http://tutorial.schornboeck.net/casts.htm</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1164756</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1164756</guid><dc:creator><![CDATA[GPC]]></dc:creator><pubDate>Mon, 30 Oct 2006 17:38:15 GMT</pubDate></item><item><title><![CDATA[Reply to In String on Tue, 31 Oct 2006 11:41:21 GMT]]></title><description><![CDATA[<p>Kann ich auch zwei Sachen verbinden?</p>
<p>Ich suche nach &quot;Life&quot; und i, wobei i ein Integer mit irgendeinem Wert ist, d.h. mein String soll z. B. &quot;Life4&quot; sein?</p>
<p>Ich will nicht einfach nach &quot;Life4&quot; suchen, das wäre zu umständlich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1165245</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1165245</guid><dc:creator><![CDATA[becks21]]></dc:creator><pubDate>Tue, 31 Oct 2006 11:41:21 GMT</pubDate></item><item><title><![CDATA[Reply to In String on Tue, 31 Oct 2006 11:53:14 GMT]]></title><description><![CDATA[<p>Bei komplizierteren Suchen, solltest Du in Erwägung ziehen eine Bibliothek für den Umgang mit <a href="http://de.wikipedia.org/wiki/Regul%C3%A4rer_Ausdruck" rel="nofollow">regulären Ausdrücken</a>, wie zum Beispiel <a href="http://boost.org/libs/regex/doc/index.html" rel="nofollow">boost::regex</a>, zu benutzen. Um das Konzept besser zu verstehen, kann es aber nicht schaden für solch einfache Dinge mal selbst einen kleinen <a href="http://de.wikipedia.org/wiki/Endlicher_Automat" rel="nofollow">endlichen Automaten</a> zu schreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1165255</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1165255</guid><dc:creator><![CDATA[Konstruktör]]></dc:creator><pubDate>Tue, 31 Oct 2006 11:53:14 GMT</pubDate></item><item><title><![CDATA[Reply to In String on Tue, 31 Oct 2006 12:17:17 GMT]]></title><description><![CDATA[<p>So kompliziert wird meine Suche nicht. Ich denke es wäre zu aufwendig eine Bibliothek zu benutzen.</p>
<p>Gibt's noch andere Möglichkeiten?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1165276</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1165276</guid><dc:creator><![CDATA[becks21]]></dc:creator><pubDate>Tue, 31 Oct 2006 12:17:17 GMT</pubDate></item><item><title><![CDATA[Reply to In String on Tue, 31 Oct 2006 13:08:54 GMT]]></title><description><![CDATA[<p>Ignoriert den Post ich war verwirrt. ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1165310</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1165310</guid><dc:creator><![CDATA[Tobi3000]]></dc:creator><pubDate>Tue, 31 Oct 2006 13:08:54 GMT</pubDate></item><item><title><![CDATA[Reply to In String on Tue, 31 Oct 2006 13:17:59 GMT]]></title><description><![CDATA[<p>mal was Einfaches <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>
<pre><code class="language-cpp">#include &lt;iostream&gt;

bool find_char(char const * SuchSring, char const * SuchText)
{
    if(SuchString == NULL || SuchText == NULL) return false;

    char * c = SuchString;
    while(c++) if(c == SuchText) return true;

    return false;
}
</code></pre>
<p>Verwendung:</p>
<pre><code class="language-cpp">int main()
{
    if(find_char(&quot;Bla Bla 1&quot;, &quot;1&quot;)) cout &lt;&lt; &quot;jep&quot; &lt;&lt; endl;
    if(find_char(&quot;Bla _ Bla...&quot;, &quot;_&quot;)) cout &lt;&lt; &quot;jep&quot; &lt;&lt; endl;

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1165316</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1165316</guid><dc:creator><![CDATA[WinieX]]></dc:creator><pubDate>Tue, 31 Oct 2006 13:17:59 GMT</pubDate></item><item><title><![CDATA[Reply to In String on Tue, 31 Oct 2006 13:23:18 GMT]]></title><description><![CDATA[<p>So einfach wie du es gern haettest, wird es nicht gehen ...</p>
<p>entweder du baust dir selber nen algo ...</p>
<p>bspw. nach &quot;Life&quot; suchen und die nachfolgenden zeichen manuell untersuchen</p>
<p>oder du verwendest Regular expressions ... und das natuerlich mit ner lib, selber implementiweren wirst das nich wollen ^^</p>
<p>Ciao ..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1165322</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1165322</guid><dc:creator><![CDATA[RHBaum]]></dc:creator><pubDate>Tue, 31 Oct 2006 13:23:18 GMT</pubDate></item><item><title><![CDATA[Reply to In String on Tue, 31 Oct 2006 13:29:41 GMT]]></title><description><![CDATA[<p>wer lesen kann, ist klar im Vortail <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>
<p>Hier noch 'n Versuch:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

bool find_char(char const * SuchSring, int Zahl)
{
    if(SuchString == NULL) return false; // String ist Leer

    char i[2];
    itoa(Zahl, i, 10);

    char * c = SuchString; 

    while(c++) if(c == i) return true;

    return false;
}

int main()
{
    int i = 4;
    if(find_char(&quot;Life4&quot;, i)) &lt;&lt; cout &quot;jep&quot; &lt;&lt; endl;
    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1165330</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1165330</guid><dc:creator><![CDATA[WinieX]]></dc:creator><pubDate>Tue, 31 Oct 2006 13:29:41 GMT</pubDate></item><item><title><![CDATA[Reply to In String on Thu, 02 Nov 2006 11:21:03 GMT]]></title><description><![CDATA[<blockquote>
<p>if(c == i) return true;</p>
</blockquote>
<p>@WinieX, diese Abfrage wird immer falsch sein, da du dort zwei verschiedene char* miteinander vergleichst, d.h. die Addressen und nicht die Stringinhalte...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1166856</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1166856</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Thu, 02 Nov 2006 11:21:03 GMT</pubDate></item><item><title><![CDATA[Reply to In String on Fri, 03 Nov 2006 11:03:54 GMT]]></title><description><![CDATA[<p>Kann man auch überprüfen, ob ein Char eine bestimmte Zeichenkette enthält?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1167584</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1167584</guid><dc:creator><![CDATA[becks21]]></dc:creator><pubDate>Fri, 03 Nov 2006 11:03:54 GMT</pubDate></item><item><title><![CDATA[Reply to In String on Fri, 03 Nov 2006 11:09:34 GMT]]></title><description><![CDATA[<p>becks21 schrieb:</p>
<blockquote>
<p>Kann man auch überprüfen, ob ein Char eine bestimmte Zeichenkette enthält?</p>
</blockquote>
<p>ja, aber man nimmt einfach std::string</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1167587</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1167587</guid><dc:creator><![CDATA[asdasdasd]]></dc:creator><pubDate>Fri, 03 Nov 2006 11:09:34 GMT</pubDate></item><item><title><![CDATA[Reply to In String on Fri, 03 Nov 2006 11:54:48 GMT]]></title><description><![CDATA[<p>Ein char kann keine Zeichenkette enthalten, dazu reicht der Platz nicht aus <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>Wenn es dir um char*'s geht (aka C-Strings), die kannst du über strcmp() (vergleiche zwei Zeichenketten), strstr() (suche Teilstrings) etc miteinander verrechnen. Aber einfacher ist es imho, stattdessen std::string zu verwenden.</p>
<p>(im Magazin gibt es auch einen Artikel darüber, was Strings alles können)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1167622</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1167622</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Fri, 03 Nov 2006 11:54:48 GMT</pubDate></item><item><title><![CDATA[Reply to In String on Fri, 03 Nov 2006 18:08:04 GMT]]></title><description><![CDATA[<p>Th schrieb:</p>
<blockquote>
<blockquote>
<p>if(c == i) return true;</p>
</blockquote>
<p>@WinieX, diese Abfrage wird immer falsch sein, da du dort zwei verschiedene char* miteinander vergleichst, d.h. die Addressen und nicht die Stringinhalte...</p>
</blockquote>
<p>ich gebs zu, hab den Code getippt ohne genauer zu gucken <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="😃"
    /> Sollte auch nur als Bsp. dienen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1167890</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1167890</guid><dc:creator><![CDATA[WinieX]]></dc:creator><pubDate>Fri, 03 Nov 2006 18:08:04 GMT</pubDate></item><item><title><![CDATA[Reply to In String on Fri, 03 Nov 2006 22:18:53 GMT]]></title><description><![CDATA[<blockquote>
<p>ich gebs zu, hab den Code getippt ohne genauer zu gucken Sollte auch nur als Bsp. dienen...</p>
</blockquote>
<p>Nein, so einen Code kann nur ein Koffer schreiben - das hat mit genau gucken nix zu tun. Entweder man kennt sich aus und weiss dass es nicht so einfach ist, oder man kennt sich nicht aus aber versucht nicht anderen was zu erzählen von was man nix versteht, oder man ist ein Koffer.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1168000</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1168000</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Fri, 03 Nov 2006 22:18:53 GMT</pubDate></item><item><title><![CDATA[Reply to In String on Sat, 04 Nov 2006 04:26:40 GMT]]></title><description><![CDATA[<p>hustbaer schrieb:</p>
<blockquote>
<blockquote>
<p>ich gebs zu, hab den Code getippt ohne genauer zu gucken Sollte auch nur als Bsp. dienen...</p>
</blockquote>
<p>Nein, so einen Code kann nur ein Koffer schreiben - das hat mit genau gucken nix zu tun. Entweder man kennt sich aus und weiss dass es nicht so einfach ist, oder man kennt sich nicht aus aber versucht nicht anderen was zu erzählen von was man nix versteht, oder man ist ein Koffer.</p>
</blockquote>
<p>Na so einen Spruch kann nur ein Anfänger bringen <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="😃"
    /><br />
Erstens: bist du selber ein Koffer und zweiten: würde ich nichts schreiben, wovon ich keine Ahnung habe! Versuch mir doch das Gegenteil zu beweisen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1168053</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1168053</guid><dc:creator><![CDATA[WinieX]]></dc:creator><pubDate>Sat, 04 Nov 2006 04:26:40 GMT</pubDate></item><item><title><![CDATA[Reply to In String on Sat, 04 Nov 2006 05:35:52 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">for(int i = 0; i&lt;strlen(text); i++) {
    if((text[i]&gt;='0' &amp;&amp; text[i]&lt;='9') || text[i]=='_') return true;
}
return false;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1168055</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1168055</guid><dc:creator><![CDATA[ganzeinfach]]></dc:creator><pubDate>Sat, 04 Nov 2006 05:35:52 GMT</pubDate></item></channel></rss>