<?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 zerlegen]]></title><description><![CDATA[<p>Hey ihr,</p>
<p>ich muss einen std::string der Form:</p>
<pre><code class="language-cpp">std::string address= &quot;TYPE=dom,home,postal,parcel:;;123 Main Street;Any Town;CA;91921-1234&quot;;
</code></pre>
<p>an den &quot;;&quot; zerlegen. Klappt fast <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="😃"
    /> mit:</p>
<pre><code class="language-cpp">while( (start = address.find_first_not_of(&quot;;&quot;, start)) != std::string::npos) 
{
  end = address.find_first_of(&quot;;&quot;, start); 
  tokens.push_back( address.substr(start, end - start) );
  start = end; 
}
</code></pre>
<p>Allerdings bekomme ich fuer ;; keine Tokens. Aber ich braeuchte da eben ein leeres Token. Es fehlt also noch was. Ich koennte jetzt noch die &quot;;&quot; durch ein &quot; ;&quot; ersetzen, aber das muss doch auch eleganter gehen.</p>
<p>Die andere Moeglichkeit waere es getline zu benutzen:</p>
<pre><code class="language-cpp">std::istringstream is(data);
	getline(is,name,';');
	getline(is,street,';');
	getline(is,city, ';');

      usw.
</code></pre>
<p>Was haltet ihr davon? Mir wuerde die erste Loesung besser gefallen...</p>
<p>Gruss<br />
Max</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/145641/string-zerlegen</link><generator>RSS for Node</generator><lastBuildDate>Fri, 11 Sep 2026 07:08:53 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/145641.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 29 Apr 2006 21:34:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to String zerlegen on Sat, 29 Apr 2006 21:34:35 GMT]]></title><description><![CDATA[<p>Hey ihr,</p>
<p>ich muss einen std::string der Form:</p>
<pre><code class="language-cpp">std::string address= &quot;TYPE=dom,home,postal,parcel:;;123 Main Street;Any Town;CA;91921-1234&quot;;
</code></pre>
<p>an den &quot;;&quot; zerlegen. Klappt fast <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="😃"
    /> mit:</p>
<pre><code class="language-cpp">while( (start = address.find_first_not_of(&quot;;&quot;, start)) != std::string::npos) 
{
  end = address.find_first_of(&quot;;&quot;, start); 
  tokens.push_back( address.substr(start, end - start) );
  start = end; 
}
</code></pre>
<p>Allerdings bekomme ich fuer ;; keine Tokens. Aber ich braeuchte da eben ein leeres Token. Es fehlt also noch was. Ich koennte jetzt noch die &quot;;&quot; durch ein &quot; ;&quot; ersetzen, aber das muss doch auch eleganter gehen.</p>
<p>Die andere Moeglichkeit waere es getline zu benutzen:</p>
<pre><code class="language-cpp">std::istringstream is(data);
	getline(is,name,';');
	getline(is,street,';');
	getline(is,city, ';');

      usw.
</code></pre>
<p>Was haltet ihr davon? Mir wuerde die erste Loesung besser gefallen...</p>
<p>Gruss<br />
Max</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1048029</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1048029</guid><dc:creator><![CDATA[__MAXIMUS__]]></dc:creator><pubDate>Sat, 29 Apr 2006 21:34:35 GMT</pubDate></item><item><title><![CDATA[Reply to String zerlegen on Sat, 29 Apr 2006 22:19:59 GMT]]></title><description><![CDATA[<p>ich hab in nem andern thread (&quot;explode&quot; war das thema) ne func dafür von muir gepostet.<br />
benutz doch die.</p>
<p>in deinem fall dann so:</p>
<pre><code class="language-cpp">...
std::string abc = &quot;bsp&quot;;
std::vector&lt;std::string&gt; def;
explode(abc, ';', def);
...
</code></pre>
<p>Mfg Shade37337</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1048037</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1048037</guid><dc:creator><![CDATA[branleb]]></dc:creator><pubDate>Sat, 29 Apr 2006 22:19:59 GMT</pubDate></item><item><title><![CDATA[Reply to String zerlegen on Sat, 29 Apr 2006 22:23:34 GMT]]></title><description><![CDATA[<p>hier is der code:</p>
<pre><code class="language-cpp">/*
Copyright (c) by Shade37337, Nanosoft

It's free to use this code in non-commercial projects or for education.
You're not allowed to use this code for commercial products.
You mustn't misrepresent this Code if you ever used it.
You musn't modify this code.
And and at last You musn't remove the Copyright notation and You're not allowed
to remove this license notation

(Sorry for my bad english, i'm still learning it....)
*/
void explode(const std::string&amp; text, const char&amp; token, std::vector&lt;std::string&gt;&amp; result)
{
    std::string                 strSub;
    std::vector&lt;std::string&gt;     res2;
    std::string::size_type        last = 0;
    std::string::size_type        temp = text.find_first_of(token, last);

    while (temp != std::string::npos)
    {
        strSub = text.substr(last, temp - last);
        if (!strSub.empty())
        {
            res2.push_back(strSub);
        }
        last = temp + 1;
        temp = text.find_first_of(token, last);
    }
    res2.push_back(text.substr(last, std::string::npos));   
    result.swap(res2);
}
</code></pre>
<p>Mfg Shade37337</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1048038</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1048038</guid><dc:creator><![CDATA[branleb]]></dc:creator><pubDate>Sat, 29 Apr 2006 22:23:34 GMT</pubDate></item><item><title><![CDATA[Reply to String zerlegen on Sun, 30 Apr 2006 14:42:26 GMT]]></title><description><![CDATA[<p>Achja, in Java bräuchtest du nur 2-3 Zeilen Code um den String in Tokens zu zerlegen... <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/1048418</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1048418</guid><dc:creator><![CDATA[xindon]]></dc:creator><pubDate>Sun, 30 Apr 2006 14:42:26 GMT</pubDate></item><item><title><![CDATA[Reply to String zerlegen on Thu, 26 Apr 2007 12:34:32 GMT]]></title><description><![CDATA[<p>xindon schrieb:</p>
<blockquote>
<p>Achja, in Java bräuchtest du nur 2-3 Zeilen Code um den String in Tokens zu zerlegen... <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>
</blockquote>
<p>In C++ auch ! Da brauchst Du sogar nur eine !<br />
Brauchst nur (genauso wie in Java auch) eine entsprechende utilityclass. :p</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1273929</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1273929</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Thu, 26 Apr 2007 12:34:32 GMT</pubDate></item></channel></rss>