<?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[String teilen]]></title><description><![CDATA[<p>Ich will aus einer langen String die mit Leerzeichen getrennt ist viele kleine machen. Wie viele einzelen Wörter in der großen String sind ist definiert(5).</p>
<p>Bsp.<br />
GroseString = &quot;Vorname Nachname Telefon Alter Ort &quot;<br />
und daraus soll werden<br />
Teil[1] = &quot;Vorname&quot;<br />
Teil[2] = &quot;Nachname&quot;<br />
Teil[3] = &quot;Telefon&quot;<br />
Teil[4] = &quot;Alter&quot;<br />
Teil[5] = &quot;Ort&quot;</p>
<p>Ich würde gerne einen Befehl haben, der das macht, aber ein Problem ist das die &quot; &quot; nicht mit angezeigt werden sollen, und ganz hinten, hinter Ort soll das Leerzeichen auch weg.</p>
<p>Wie geht das <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/184331/string-teilen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 16:01:57 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/184331.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 14 Jun 2007 10:38:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to String teilen on Thu, 14 Jun 2007 10:45:24 GMT]]></title><description><![CDATA[<p>Ich will aus einer langen String die mit Leerzeichen getrennt ist viele kleine machen. Wie viele einzelen Wörter in der großen String sind ist definiert(5).</p>
<p>Bsp.<br />
GroseString = &quot;Vorname Nachname Telefon Alter Ort &quot;<br />
und daraus soll werden<br />
Teil[1] = &quot;Vorname&quot;<br />
Teil[2] = &quot;Nachname&quot;<br />
Teil[3] = &quot;Telefon&quot;<br />
Teil[4] = &quot;Alter&quot;<br />
Teil[5] = &quot;Ort&quot;</p>
<p>Ich würde gerne einen Befehl haben, der das macht, aber ein Problem ist das die &quot; &quot; nicht mit angezeigt werden sollen, und ganz hinten, hinter Ort soll das Leerzeichen auch weg.</p>
<p>Wie geht das <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1305546</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1305546</guid><dc:creator><![CDATA[Stratege993]]></dc:creator><pubDate>Thu, 14 Jun 2007 10:45:24 GMT</pubDate></item><item><title><![CDATA[Reply to String teilen on Thu, 14 Jun 2007 10:41:39 GMT]]></title><description><![CDATA[<p>Schau hier: <a href="http://www.boost.org/doc/html/string_algo/usage.html#id1638536" rel="nofollow">http://www.boost.org/doc/html/string_algo/usage.html#id1638536</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1305548</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1305548</guid><dc:creator><![CDATA[David_pb]]></dc:creator><pubDate>Thu, 14 Jun 2007 10:41:39 GMT</pubDate></item><item><title><![CDATA[Reply to String teilen on Thu, 14 Jun 2007 10:45:06 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>das kann man recht komfortabel mit std::istringstream machen (ohne boost nutzen zu müssen).<br />
(BTW: &quot;GString&quot; kenne ich nicht in dem Zusammenhang, beziehe mich auf std::string)</p>
<p>Nicht getestet ... irgendwie so:</p>
<pre><code class="language-cpp">std::string s = &quot;Vorname Nachname Telefon Alter Ort &quot;;
std::istringstream in(s);
std::vector&lt;std::string&gt; Teile(5);
for(int i=0; i&lt;5 &amp;&amp; (in &gt;&gt; Teile[i]); ++i);
</code></pre>
<p>Leider muss ich jetzt fix weg, aber vllt. suchst Du mal im Forum dazu.</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1305549</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1305549</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Thu, 14 Jun 2007 10:45:06 GMT</pubDate></item><item><title><![CDATA[Reply to String teilen on Thu, 14 Jun 2007 11:21:36 GMT]]></title><description><![CDATA[<p>Ich bin sher neu bei dem Qulletext sagt C++ aber das er nicht std kennt. Muss ich noch irgendwas machen? Vieleicht irgenwas includen?<br />
Ist bistimmt eine blöde frage,würde aber gerne eine Antwort haben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1305583</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1305583</guid><dc:creator><![CDATA[Stratege993]]></dc:creator><pubDate>Thu, 14 Jun 2007 11:21:36 GMT</pubDate></item><item><title><![CDATA[Reply to String teilen on Thu, 14 Jun 2007 11:30:10 GMT]]></title><description><![CDATA[<p>Ok, jetzt habe ich das programm zum laufen bekommen beim den Ausgeben in ein Label sagt er jetzt aber:</p>
<p>E 2034 Konvertierung von '_STL::string' nach 'AnsiString' nicht möglich</p>
<p>Wie kann ich das Konfertieren?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1305593</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1305593</guid><dc:creator><![CDATA[Stratege993]]></dc:creator><pubDate>Thu, 14 Jun 2007 11:30:10 GMT</pubDate></item><item><title><![CDATA[Reply to String teilen on Thu, 14 Jun 2007 11:53:32 GMT]]></title><description><![CDATA[<p>Stratege993 schrieb:</p>
<blockquote>
<p>Ok, jetzt habe ich das programm zum laufen bekommen beim den Ausgeben in ein Label sagt er jetzt aber:</p>
<p>E 2034 Konvertierung von '_STL::string' nach 'AnsiString' nicht möglich</p>
<p>Einfach in der entsprechenden Zeile in c_str() hier std::string setzen ..<br />
Wie kann ich das Konfertieren?</p>
</blockquote>
<pre><code class="language-cpp">Label1-&gt;Caption = mystring.c_str();
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1305619</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1305619</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Thu, 14 Jun 2007 11:53:32 GMT</pubDate></item><item><title><![CDATA[Reply to String teilen on Thu, 14 Jun 2007 11:58:20 GMT]]></title><description><![CDATA[<p>OK es geht.<br />
Danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1305625</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1305625</guid><dc:creator><![CDATA[Stratege993]]></dc:creator><pubDate>Thu, 14 Jun 2007 11:58:20 GMT</pubDate></item><item><title><![CDATA[Reply to String teilen on Thu, 14 Jun 2007 14:22:23 GMT]]></title><description><![CDATA[<p>Stratege993 schrieb:</p>
<blockquote>
<p>Ich bin sher neu bei dem Qulletext sagt C++ aber das er nicht std kennt. Muss ich noch irgendwas machen? Vieleicht irgenwas includen?<br />
Ist bistimmt eine blöde frage,würde aber gerne eine Antwort haben.</p>
</blockquote>
<p>Hi,</p>
<p>ja sorry, musste gerade dringend weg.</p>
<p>Hier eine getestete Version (ohne &quot;eye candy&quot;):</p>
<pre><code class="language-cpp">#include &lt;string&gt;
using std::string;

#include &lt;vector&gt;
using std::vector;

#include &lt;sstream&gt;
using std::istringstream;

#include &lt;iostream&gt;
using std::cout;

using std::size_t;

int main (int argc, char **argv)
{
   string s = &quot;Vorname Nachname Telefon Alter Ort &quot;;
   istringstream in(s);
   vector&lt;string&gt; Teile(5); // 5 Plätze vorreservieren

   // solange auslesen, bis wir 5 haben oder das Einlesen fehlschlägt
   for(size_t i=0; i&lt;5 &amp;&amp; (in &gt;&gt; Teile[i]); ++i);  

   // Ausgeben
   for(size_t i=0; i&lt;Teile.size(); ++i) cout &lt;&lt; i &lt;&lt; &quot;. String &quot; &lt;&lt; Teile[i] &lt;&lt; &quot;\n&quot;;

   return 0;
}
</code></pre>
<p>... und noch eine &quot;eye candy&quot;-Variante:</p>
<pre><code class="language-cpp">#include &lt;string&gt;
using std::string;

#include &lt;vector&gt;
using std::vector;

#include &lt;sstream&gt;
using std::istringstream;

#include &lt;iostream&gt;
using std::cout;

#include &lt;algorithm&gt;
using std::copy;

#include &lt;iterator&gt;
using std::ostream_iterator;
using std::istream_iterator;

using std::size_t;

int main (int argc, char **argv)
{
   string s = &quot;Vorname Nachname Telefon Alter Ort &quot;;
   istringstream in(s);
   vector&lt;string&gt; Teile;

   // Einlesen in Teile:      
   copy(istream_iterator&lt;string&gt;(in), istream_iterator&lt;string&gt;(), back_inserter(Teile));

   // Ausgabe nach cout
   copy(Teile.begin(), Teile.end(), ostream_iterator&lt;string&gt;(cout, &quot; &quot;));

   return 0;
}
</code></pre>
<p>Mit dem &quot;iteratoren-Gedöns&quot; sagt man dem Compiler, dass man aus einem Stream oder Container &quot;Stück-für-Stück&quot; Inhalte auslesen will und back_inserter &quot;weiß&quot;, wie man an einen Container ein weiteres Element anhängt....</p>
<p>Aber um das lesen zu können, braucht man schon einiges an C++-Erfahrung...<br />
aber EIN Vorteil der zweiten Variante ist, dass man nirgends das Wissen braucht, wie viele &quot;Tokens&quot; im String s stecken. Er ist also flexibler und robuster.</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1305752</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1305752</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Thu, 14 Jun 2007 14:22:23 GMT</pubDate></item></channel></rss>