<?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[Stringverarbeitung]]></title><description><![CDATA[<p>Guten Abend,</p>
<p>ich habe versucht die Länge eines Strings zu ermittlen, ich habe irgendwo gelesen das in einem String am Ende immer noch ein \n vorhanden ist, also hab ich danach suchen wollen, aber er findet nichts, stattdessen schließt er alle sofort wieder.</p>
<pre><code class="language-csharp">int main()
    {
    string text;
    int zaehler;

    cout&lt;&lt;&quot;Geben Sie einen Text ein!&quot;&lt;&lt;endl;
    cin&gt;&gt;text;

    string::size_type f = text.find(&quot;b&quot;);
    string::size_type i = text.find('\n');
    text.erase(i,1);
    cout&lt;&lt;i+1&lt;&lt;endl; 
    cout&lt;&lt;f+1&lt;&lt;endl;   

    getch();

    }
</code></pre>
<p>Jemand eine Idee, wie ich die Länge ermitteln könnte?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/187353/stringverarbeitung</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 15:34:53 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/187353.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 18 Jul 2007 18:56:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Stringverarbeitung on Wed, 18 Jul 2007 18:56:06 GMT]]></title><description><![CDATA[<p>Guten Abend,</p>
<p>ich habe versucht die Länge eines Strings zu ermittlen, ich habe irgendwo gelesen das in einem String am Ende immer noch ein \n vorhanden ist, also hab ich danach suchen wollen, aber er findet nichts, stattdessen schließt er alle sofort wieder.</p>
<pre><code class="language-csharp">int main()
    {
    string text;
    int zaehler;

    cout&lt;&lt;&quot;Geben Sie einen Text ein!&quot;&lt;&lt;endl;
    cin&gt;&gt;text;

    string::size_type f = text.find(&quot;b&quot;);
    string::size_type i = text.find('\n');
    text.erase(i,1);
    cout&lt;&lt;i+1&lt;&lt;endl; 
    cout&lt;&lt;f+1&lt;&lt;endl;   

    getch();

    }
</code></pre>
<p>Jemand eine Idee, wie ich die Länge ermitteln könnte?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1328011</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1328011</guid><dc:creator><![CDATA[Cr3at0r]]></dc:creator><pubDate>Wed, 18 Jul 2007 18:56:06 GMT</pubDate></item><item><title><![CDATA[Reply to Stringverarbeitung on Wed, 18 Jul 2007 19:33:34 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;

int main()
{
    std::string Str;
    std::cin &gt;&gt; Str; // Falls du mehr als nur bis zum Leerzeichen einlesen wilsst musst du auf getline umsteigen!
    std::cout &lt;&lt; Str.length() &lt;&lt; std::endl;
    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1328043</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1328043</guid><dc:creator><![CDATA[lololololol]]></dc:creator><pubDate>Wed, 18 Jul 2007 19:33:34 GMT</pubDate></item><item><title><![CDATA[Reply to Stringverarbeitung on Wed, 18 Jul 2007 19:45:30 GMT]]></title><description><![CDATA[<p>Wie kann ich auf eine bestimmte Stelle eines Strings zugreifen. Also wenn ich von dem String text mit dem Inhalt &quot;Test&quot; auf das &quot;e&quot; zugreifen möchte?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1328055</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1328055</guid><dc:creator><![CDATA[Cr3at0r]]></dc:creator><pubDate>Wed, 18 Jul 2007 19:45:30 GMT</pubDate></item><item><title><![CDATA[Reply to Stringverarbeitung on Wed, 18 Jul 2007 19:56:36 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Dazu benutzt du den []-Operator von string</p>
<pre><code class="language-cpp">string Wort = &quot;Test&quot;;
char Zeichen = Wort[1];
</code></pre>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1328061</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1328061</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Wed, 18 Jul 2007 19:56:36 GMT</pubDate></item><item><title><![CDATA[Reply to Stringverarbeitung on Wed, 18 Jul 2007 20:24:43 GMT]]></title><description><![CDATA[<p>Habe jetzt folgenden Code:</p>
<pre><code class="language-csharp">int main()
    {
    string text;
    int zaehler;
    char buchstabe;
    int i;
    int e;
    int alphaa;

    cout&lt;&lt;&quot;Geben Sie einen Text ein!&quot;&lt;&lt;endl;
    cin&gt;&gt;text;

    for (i=0;text.length();i++)
    {
        for (e=97;122;e++)
        {
            buchstabe=text[i];
            if (char(e)=buchstabe)
            {
            alphaa=alphaa+1;                       
            }            
        }         
    }

    cout&lt;&lt;alphaa&lt;&lt;endl;   

    getch();
    return 0;    
    }
</code></pre>
<p>Nun ist das Problem das er zwar ohne Fehlermeldungen durch kompiliert, ich aber wenn ich einen Text eingabe und Enter drücke er einen Zeilenumbruch macht, er aber nichts ausgibt, genauso wenig sich das Fenstr, über eine beliebige taste schließen lässt. Woran kann das liegen?</p>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1328075</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1328075</guid><dc:creator><![CDATA[Cr3at0r]]></dc:creator><pubDate>Wed, 18 Jul 2007 20:24:43 GMT</pubDate></item><item><title><![CDATA[Reply to Stringverarbeitung on Wed, 18 Jul 2007 20:31:36 GMT]]></title><description><![CDATA[<p>Also:<br />
\n steht für &quot;New Line&quot; und nicht für Null-Terminierung.<br />
\0 ist das was du suchst.<br />
da \0 == 0 ist:</p>
<pre><code class="language-cpp">char arr[] = &quot;..... oha .....&quot;;

std::size_t len = 0;
while (arr[len]) ++len;
std::cout &lt;&lt; arr &lt;&lt; &quot; =&gt; &quot; &lt;&lt; len &lt;&lt; &quot; Zeichen&quot; &lt;&lt; std::endl;
</code></pre>
<p>... für das ganze gibt es aber std::strlen (Header: &lt;cstring&gt;) bzw. bei std::string die Memberfunktion length().</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1328080</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1328080</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Wed, 18 Jul 2007 20:31:36 GMT</pubDate></item><item><title><![CDATA[Reply to Stringverarbeitung on Wed, 18 Jul 2007 20:39:17 GMT]]></title><description><![CDATA[<blockquote>
<p>Nun ist das Problem das er zwar ohne Fehlermeldungen durch kompiliert, ich aber wenn ich einen Text eingabe und Enter drücke er einen Zeilenumbruch macht, er aber nichts ausgibt, genauso wenig sich das Fenstr, über eine beliebige taste schließen lässt. Woran kann das liegen?</p>
</blockquote>
<p>Alle beiden Schleifen und die if-Abfrage sind falsch, lies dir am besten nochmal ein Tutorial durch <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="🙂"
    /> Habs dir bereits ausgebessert:</p>
<pre><code class="language-cpp">for (i=0;i&lt;text.length();i++)
</code></pre>
<pre><code class="language-cpp">for (e=97;e&lt;122;e++)
</code></pre>
<pre><code class="language-cpp">if (char(e)==buchstabe)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1328086</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1328086</guid><dc:creator><![CDATA[mikey]]></dc:creator><pubDate>Wed, 18 Jul 2007 20:39:17 GMT</pubDate></item><item><title><![CDATA[Reply to Stringverarbeitung on Wed, 18 Jul 2007 20:57:14 GMT]]></title><description><![CDATA[<p>Oh man, dabei dacht ich hätte die richtige Synthax, nervt mich jetzt ein wenig...</p>
<p>Nachdem ich die doofen Fehler behoben habe und das Programm getestet hab, kam zwar endlich ein Wert aber was für einer, es ist dauerhaft: 2293853.<br />
Deutet für mich auf die Schleifen hin.</p>
<p>Nur weiß ich nicht wie er auf diese gigantische Summe kommt, woher kann das kommen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1328097</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1328097</guid><dc:creator><![CDATA[Cr3at0r]]></dc:creator><pubDate>Wed, 18 Jul 2007 20:57:14 GMT</pubDate></item><item><title><![CDATA[Reply to Stringverarbeitung on Wed, 18 Jul 2007 21:06:12 GMT]]></title><description><![CDATA[<p>Ich verstehe die Logik hinter deinem Programm nicht wirklich, aber der Grund mit der großen Zahl ist ganz simpel. Du legst die Variable alphaa folgendermaßen an:</p>
<pre><code class="language-cpp">int alphaa;
</code></pre>
<p>...das bedeutet aber, dass der Speicherplatz für diese Variable lediglich reserviert, nicht aber dessen Inhalt gelöscht wird. Du musst also alphaa auf 0 setzen, um dann vernünftig damit arbeiten zu können:</p>
<pre><code class="language-cpp">int alphaa = 0;
</code></pre>
<p>Merk dir das bei jeder Variable, du musst sie immer mit einem Wert vorbelegen, da der Inhalt sonst undefiniert ist <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/1328101</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1328101</guid><dc:creator><![CDATA[mikey]]></dc:creator><pubDate>Wed, 18 Jul 2007 21:06:12 GMT</pubDate></item><item><title><![CDATA[Reply to Stringverarbeitung on Thu, 19 Jul 2007 00:08:30 GMT]]></title><description><![CDATA[<p>Die Logik von mir zur Übung war, dass ich aus einem String zb &quot;a&quot; heraus zählen kann. *G*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1328139</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1328139</guid><dc:creator><![CDATA[Cr3at0r]]></dc:creator><pubDate>Thu, 19 Jul 2007 00:08:30 GMT</pubDate></item><item><title><![CDATA[Reply to Stringverarbeitung on Thu, 19 Jul 2007 09:31:33 GMT]]></title><description><![CDATA[<p>Nja ... das zählen würde ich in C und C++ jeweils anders lösen ^^<br />
also C-Stylig:</p>
<pre><code class="language-cpp">char arr[] = &quot;My Text contains some e's!&quot;;
std::size_t count = 0;
while (*arr){ if (*arr == 'e') ++count; ++arr;}

// oder
count = 0;
for (std::size_t pos = 0; pos &lt; std::strlen(arr); ++pos)
    if (arr[pos] == 'e') ++count;
</code></pre>
<p>...</p>
<p>C++-Style:</p>
<pre><code class="language-cpp">std::string my_text(&quot;My Text contains some a's!&quot;);
std::size_t count = 0;
for (std::size_t pos = my_text.find_first_of('a', 0); pos != std::string::npos; pos = my_text.find_first_of('a', ++pos)) ++count;
</code></pre>
<p>...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1328315</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1328315</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Thu, 19 Jul 2007 09:31:33 GMT</pubDate></item><item><title><![CDATA[Reply to Stringverarbeitung on Thu, 19 Jul 2007 09:35:53 GMT]]></title><description><![CDATA[<p>(D)Evil schrieb:</p>
<blockquote>
<p>C++-Style:</p>
<pre><code class="language-cpp">std::string my_text(&quot;My Text contains some a's!&quot;);
std::size_t count = 0;
for (std::size_t pos = my_text.find_first_of('a', 0); pos != std::string::npos; pos = my_text.find_first_of('a', ++pos)) ++count;
</code></pre>
<p>...</p>
</blockquote>
<p>Also das geht doch noch kürzer:</p>
<pre><code class="language-cpp">std::string my_text=&quot;My Text contains some x's!&quot;;
std::size_t count = std::count(my_text.begin(),my_text.end(),'x');
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1328322</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1328322</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 19 Jul 2007 09:35:53 GMT</pubDate></item><item><title><![CDATA[Reply to Stringverarbeitung on Thu, 19 Jul 2007 13:27:15 GMT]]></title><description><![CDATA[<p>Die vereinfachten Zeilen sind mir noch etwas zu wirr, für den Anfang. Hab das jetzt mit for to do schleifen gemacht und es geht auch. <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>
<p>Vielen Dank für die zahlreichen Antworten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1328557</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1328557</guid><dc:creator><![CDATA[Cr3at0r]]></dc:creator><pubDate>Thu, 19 Jul 2007 13:27:15 GMT</pubDate></item><item><title><![CDATA[Reply to Stringverarbeitung on Fri, 20 Jul 2007 09:44:22 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">std::string my_text=&quot;My Text contains some x's!&quot;;
std::size_t count = std::count(my_text.begin(),my_text.end(),'x');
</code></pre>
<p>Es wird eine Stringvariable initialisiert. Dann geht der Zähler (count) von Wortanfang (.begin()) bis Wortende (.end()) durch den String und zählt die angegebenen Zeichen die in (' ') eingeschlossen sind. Das war es auch schon.</p>
<p>Count ist also eine Art Dienstleistungsprogramm für den String (und für andere Typen). Count = Zähler. Man muss nur angeben was man suchen will.</p>
<p><a href="http://www.cppreference.com/cppalgorithm/count.html" rel="nofollow">http://www.cppreference.com/cppalgorithm/count.html</a></p>
<p>Count kann aber noch vielmehr, siehe Referenz.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1329085</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1329085</guid><dc:creator><![CDATA[countword]]></dc:creator><pubDate>Fri, 20 Jul 2007 09:44:22 GMT</pubDate></item><item><title><![CDATA[Reply to Stringverarbeitung on Fri, 20 Jul 2007 09:47:40 GMT]]></title><description><![CDATA[<p>countword schrieb:</p>
<blockquote>
<p>Count ist also eine Art Dienstleistungsprogramm für den String (und für andere Typen). Count = Zähler. Man muss nur angeben was man suchen will.</p>
</blockquote>
<p>Auch eine interresante Sichtweise auf die STL-Algorithmen <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1329090</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1329090</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Fri, 20 Jul 2007 09:47:40 GMT</pubDate></item></channel></rss>