<?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[CSV sscanf]]></title><description><![CDATA[<p>Hallo<br />
Ich habe eine CSV die ungefähr so aussieht:<br />
string;string1;string2;string3;</p>
<p>Es kann aber auch sein das sie so aussieht:<br />
string;;string2;string3<br />
Also das ein Feld leer ist.<br />
Nun will ich die CSV auslesen und mit sscanf in die einzelnen Strings aufteilen:</p>
<pre><code class="language-cpp">swscanf(zeile, L&quot;%[^;];%[^;];%[^;];%[^;&rsqb;&rsqb;&quot;, string,string1,string2,string3);
</code></pre>
<p>Das funktioniert aber nur wenn etwas zwischen den Semikolons steht. Wenn nichts dasteht schlägt es fehl. Wenn z.B das 3. Feld leer ist, dann liest er nur bis zum Dritten Feld ein und nicht weiter.</p>
<p>Bitte um Hilfe.</p>
<p>MfG Tim</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/244824/csv-sscanf</link><generator>RSS for Node</generator><lastBuildDate>Sat, 19 Sep 2026 04:00:24 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/244824.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 06 Jul 2009 10:54:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to CSV sscanf on Mon, 06 Jul 2009 10:54:35 GMT]]></title><description><![CDATA[<p>Hallo<br />
Ich habe eine CSV die ungefähr so aussieht:<br />
string;string1;string2;string3;</p>
<p>Es kann aber auch sein das sie so aussieht:<br />
string;;string2;string3<br />
Also das ein Feld leer ist.<br />
Nun will ich die CSV auslesen und mit sscanf in die einzelnen Strings aufteilen:</p>
<pre><code class="language-cpp">swscanf(zeile, L&quot;%[^;];%[^;];%[^;];%[^;&rsqb;&rsqb;&quot;, string,string1,string2,string3);
</code></pre>
<p>Das funktioniert aber nur wenn etwas zwischen den Semikolons steht. Wenn nichts dasteht schlägt es fehl. Wenn z.B das 3. Feld leer ist, dann liest er nur bis zum Dritten Feld ein und nicht weiter.</p>
<p>Bitte um Hilfe.</p>
<p>MfG Tim</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1737849</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1737849</guid><dc:creator><![CDATA[Fatal Error appears]]></dc:creator><pubDate>Mon, 06 Jul 2009 10:54:35 GMT</pubDate></item><item><title><![CDATA[Reply to CSV sscanf on Mon, 06 Jul 2009 11:04:40 GMT]]></title><description><![CDATA[<p>Also ich schätze, da kommst du mit sscanf nicht sehr weit. Das verlässt sich normalerweise darauf, dass die Datei so aufgebaut ist, wie von dir angegeben. Und wenn der Aufbau variiert... Vielleicht kannst du ja schnell einen eigenen, kleinen Parser schreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1737857</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1737857</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Mon, 06 Jul 2009 11:04:40 GMT</pubDate></item><item><title><![CDATA[Reply to CSV sscanf on Mon, 06 Jul 2009 11:06:30 GMT]]></title><description><![CDATA[<p>Der Aufbau bleibt ja immer gleich nur es kann sein, dass mal nichts zwischen den Semikolons steht...??!!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1737859</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1737859</guid><dc:creator><![CDATA[Fatal Error appears]]></dc:creator><pubDate>Mon, 06 Jul 2009 11:06:30 GMT</pubDate></item><item><title><![CDATA[Reply to CSV sscanf on Mon, 06 Jul 2009 11:30:15 GMT]]></title><description><![CDATA[<p>Ich hab davon keine Ahnung, würde aber versuchen, vor dem Auslesen Ersetzungen zurchzuführen, ala</p>
<pre><code class="language-cpp">replace_all(&quot;;;&quot;, &quot;; ;&quot;);
</code></pre>
<p>Das Leerzecihen sollte doch als korrekter String durchgehen, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1737878</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1737878</guid><dc:creator><![CDATA[KÖTER]]></dc:creator><pubDate>Mon, 06 Jul 2009 11:30:15 GMT</pubDate></item><item><title><![CDATA[Reply to CSV sscanf on Mon, 06 Jul 2009 11:41:55 GMT]]></title><description><![CDATA[<p>Keine schlechte Idee. Aber dann würde ja im string dann später ein Leerzeichen stehen und dass will ich nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1737887</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1737887</guid><dc:creator><![CDATA[Fatal Error appears]]></dc:creator><pubDate>Mon, 06 Jul 2009 11:41:55 GMT</pubDate></item><item><title><![CDATA[Reply to CSV sscanf on Mon, 06 Jul 2009 11:44:26 GMT]]></title><description><![CDATA[<p>Fatal Error appears schrieb:</p>
<blockquote>
<p>Der Aufbau bleibt ja immer gleich nur es kann sein, dass mal nichts zwischen den Semikolons steht...??!!</p>
</blockquote>
<p>Das ist schon ein kleiner Unterschied. Mein Tipp: lies eine ganze Zeile ein und pars es mit einer kleinen RegExp <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/1737889</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1737889</guid><dc:creator><![CDATA[Blue-Tiger]]></dc:creator><pubDate>Mon, 06 Jul 2009 11:44:26 GMT</pubDate></item><item><title><![CDATA[Reply to CSV sscanf on Mon, 06 Jul 2009 11:46:17 GMT]]></title><description><![CDATA[<p>Fatal Error appears schrieb:</p>
<blockquote>
<p>Keine schlechte Idee. Aber dann würde ja im string dann später ein Leerzeichen stehen und dass will ich nicht.</p>
</blockquote>
<pre><code class="language-cpp">if(string == &quot; &quot;) string = &quot;&quot;;
</code></pre>
<p>oder so in der Art.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1737891</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1737891</guid><dc:creator><![CDATA[KÖTER]]></dc:creator><pubDate>Mon, 06 Jul 2009 11:46:17 GMT</pubDate></item><item><title><![CDATA[Reply to CSV sscanf on Mon, 06 Jul 2009 11:46:51 GMT]]></title><description><![CDATA[<p>Boost.Regex ist dein Freund!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1737892</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1737892</guid><dc:creator><![CDATA[Sloboda]]></dc:creator><pubDate>Mon, 06 Jul 2009 11:46:51 GMT</pubDate></item><item><title><![CDATA[Reply to CSV sscanf on Mon, 06 Jul 2009 11:50:27 GMT]]></title><description><![CDATA[<p>Ähm hast du da ein kleines Beispiel.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1737893</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1737893</guid><dc:creator><![CDATA[Fatal Error appears]]></dc:creator><pubDate>Mon, 06 Jul 2009 11:50:27 GMT</pubDate></item><item><title><![CDATA[Reply to CSV sscanf on Mon, 06 Jul 2009 11:58:57 GMT]]></title><description><![CDATA[<p>Ich finde da Boost.Regexp bissi mit Kanonen auf Spatzen geschossen...<br />
Eine eigene kleine Funktion, die mit std-c++ eine Zeile deines Programms nach &quot;;&quot; durchsucht, und dann per Referenz angegebenen Strings zuweist ist nicht allzuschwer.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1737898</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1737898</guid><dc:creator><![CDATA[KÖTER]]></dc:creator><pubDate>Mon, 06 Jul 2009 11:58:57 GMT</pubDate></item><item><title><![CDATA[Reply to CSV sscanf on Mon, 06 Jul 2009 12:06:58 GMT]]></title><description><![CDATA[<p>KÖTER schrieb:</p>
<blockquote>
<p>Ich finde da Boost.Regexp bissi mit Kanonen auf Spatzen geschossen...<br />
Eine eigene kleine Funktion, die mit std-c++ eine Zeile deines Programms nach &quot;;&quot; durchsucht, und dann per Referenz angegebenen Strings zuweist ist nicht allzuschwer.</p>
</blockquote>
<p>FullACK</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1737903</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1737903</guid><dc:creator><![CDATA[jencas]]></dc:creator><pubDate>Mon, 06 Jul 2009 12:06:58 GMT</pubDate></item><item><title><![CDATA[Reply to CSV sscanf on Mon, 06 Jul 2009 12:09:27 GMT]]></title><description><![CDATA[<p>Wenn schon boost, dann fände ich boost::tokenizer hier besser.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1737905</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1737905</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Mon, 06 Jul 2009 12:09:27 GMT</pubDate></item><item><title><![CDATA[Reply to CSV sscanf on Mon, 06 Jul 2009 12:24:01 GMT]]></title><description><![CDATA[<p>gibt es keine einfachere Methode als mit boost?</p>
<p>MfG Tim</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1737912</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1737912</guid><dc:creator><![CDATA[Fatal Error appears]]></dc:creator><pubDate>Mon, 06 Jul 2009 12:24:01 GMT</pubDate></item><item><title><![CDATA[Reply to CSV sscanf on Mon, 06 Jul 2009 12:25:26 GMT]]></title><description><![CDATA[<p>Fatal Error appears schrieb:</p>
<blockquote>
<p>gibt es keine einfachere Methode als mit boost?</p>
<p>MfG Tim</p>
</blockquote>
<p>Die wurde schon genannt. Eine eigene, kleine Funktion.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1737913</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1737913</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Mon, 06 Jul 2009 12:25:26 GMT</pubDate></item><item><title><![CDATA[Reply to CSV sscanf on Mon, 06 Jul 2009 12:31:23 GMT]]></title><description><![CDATA[<p>KÖTER schrieb:</p>
<blockquote>
<p>Ich finde da Boost.Regexp bissi mit Kanonen auf Spatzen geschossen...<br />
Eine eigene kleine Funktion, die mit std-c++ eine Zeile deines Programms nach &quot;;&quot; durchsucht, und dann per Referenz angegebenen Strings zuweist ist nicht allzuschwer.</p>
</blockquote>
<p>FullACK<br />
Dürfte auch wesentlich schneller laufen, als mit einem RegExp Ausdruck. Da wäre sogar Boost.Xpressive zu langsam im Vergleich.</p>
<p>Mit <a href="http://www.cplusplus.com/reference/string/getline/" rel="nofollow">std::getline</a> alles einlesen, danach den <code>std::string</code> mit <a href="http://www.cplusplus.com/reference/string/string/find/" rel="nofollow">std::string::find</a> und <a href="http://www.cplusplus.com/reference/string/string/substr/" rel="nofollow">std::string::substr</a> auseinandernehmen.<br />
Bei <code>std::string::find</code> sollte man im übrigen bemerken, dass man ab einer bestimmten Position suchen kann. Sehr hilfreich um das ganze in einer Schleife zu realisieren <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>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1737918</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1737918</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Mon, 06 Jul 2009 12:31:23 GMT</pubDate></item><item><title><![CDATA[Reply to CSV sscanf on Mon, 06 Jul 2009 12:45:53 GMT]]></title><description><![CDATA[<p>Ok danke hat geklappt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1737926</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1737926</guid><dc:creator><![CDATA[Fatal Error appears]]></dc:creator><pubDate>Mon, 06 Jul 2009 12:45:53 GMT</pubDate></item></channel></rss>