<?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 parsen]]></title><description><![CDATA[<p>hallo zusammen,</p>
<p>ich lese in mein programm befehle von einer &quot;skriptdatei&quot; ein.<br />
Ein befehl ist von dieser struktur:</p>
<pre><code>befehlname(1,2,3,4,5,6,7)
</code></pre>
<p>die parameter sollen alle als integer interpretiert werden</p>
<p>meine erste intuitive idee wäre gewesen:<br />
ich suche das erste vorkommen von &quot;(&quot; mit find_first_of()<br />
dann suche ich nach dem ersten vorkommen von &quot;,&quot;<br />
wenn ich diese beiden positionen habe lese ich mittels substr das was dazwischen ist heraus.</p>
<p>danach lösche ich bis inklusive zum ersten vorkommen von &quot;,&quot; alles weg und suche wieder nach dem ersten &quot;,&quot; das könnt ich dann irgendwie in eine schleife packen (parameter anzahl ist immer die gleiche).</p>
<p>das erscheinst mir aber irgendwie umständlich....deshalb wollte ich fragen wie man sowas am besten angeht...???</p>
<p>hinzukommt dass das problem nicht gleich abkacken soll wenn dazwischen noch leerzeichen sind usw.....</p>
<p>lg<br />
cr</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/238044/string-parsen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 04:06:59 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/238044.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 05 Apr 2009 17:32:57 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to String parsen on Sun, 05 Apr 2009 17:41:42 GMT]]></title><description><![CDATA[<p>hallo zusammen,</p>
<p>ich lese in mein programm befehle von einer &quot;skriptdatei&quot; ein.<br />
Ein befehl ist von dieser struktur:</p>
<pre><code>befehlname(1,2,3,4,5,6,7)
</code></pre>
<p>die parameter sollen alle als integer interpretiert werden</p>
<p>meine erste intuitive idee wäre gewesen:<br />
ich suche das erste vorkommen von &quot;(&quot; mit find_first_of()<br />
dann suche ich nach dem ersten vorkommen von &quot;,&quot;<br />
wenn ich diese beiden positionen habe lese ich mittels substr das was dazwischen ist heraus.</p>
<p>danach lösche ich bis inklusive zum ersten vorkommen von &quot;,&quot; alles weg und suche wieder nach dem ersten &quot;,&quot; das könnt ich dann irgendwie in eine schleife packen (parameter anzahl ist immer die gleiche).</p>
<p>das erscheinst mir aber irgendwie umständlich....deshalb wollte ich fragen wie man sowas am besten angeht...???</p>
<p>hinzukommt dass das problem nicht gleich abkacken soll wenn dazwischen noch leerzeichen sind usw.....</p>
<p>lg<br />
cr</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1691358</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1691358</guid><dc:creator><![CDATA[cryps]]></dc:creator><pubDate>Sun, 05 Apr 2009 17:41:42 GMT</pubDate></item><item><title><![CDATA[Reply to String parsen on Sun, 05 Apr 2009 17:48:09 GMT]]></title><description><![CDATA[<p>Hi!</p>
<p>boost::spirit könnte dir da weiterhelfen. Damit kann man relativ einfach Parser bauen. Es gibt dazu auch zwei Artikel im Magazin:<br />
<a href="http://magazin.c-plusplus.net/artikel/Boost%3A%3ASpirit%20-%20Eine%20Einf%FChrung" rel="nofollow">Spirit</a><br />
<a href="http://magazin.c-plusplus.net/artikel/Ein%20%DCberblick%20%FCber%20Spirit2" rel="nofollow">Spirit2</a> (verlinkt auch auf den anderen Artikel)</p>
<p>Ansonsten könntest du in diesem Fall eventuell auch einen regulären Ausdruck (boost::regex) nutzen.</p>
<p>Greetz</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1691368</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1691368</guid><dc:creator><![CDATA[Vellas]]></dc:creator><pubDate>Sun, 05 Apr 2009 17:48:09 GMT</pubDate></item><item><title><![CDATA[Reply to String parsen on Sun, 05 Apr 2009 17:51:40 GMT]]></title><description><![CDATA[<p>Mit den Stream-Operatoren kommst du da schon relativ weit. Für anspruchsvolleres Parsen eignet sich Boost.Regex oder je nach dem sogar Boost.Spirit.</p>
<p>Fürs erste könnten dir diese beiden Threads hilfreich sein:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-210160.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-210160.html</a><br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-176361.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-176361.html</a></p>
<p>Achte besonders auf die Posts von Werner Salomon, er kennt sich nämlich sehr gut mit Streams 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>
]]></description><link>https://www.c-plusplus.net/forum/post/1691370</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1691370</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sun, 05 Apr 2009 17:51:40 GMT</pubDate></item><item><title><![CDATA[Reply to String parsen on Mon, 06 Apr 2009 12:28:52 GMT]]></title><description><![CDATA[<p>Hallo</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;

float convertToInt(std::string Num)
{
	if((strlen(Num.c_str())) &gt; 0)
	{
		int x = atoi(Num.c_str());
		return x;
	}
	else
	{
		Num.clear();
		return 0;
	}
}

std::string const getWord(std::string Line, int Pos) 
{
	std::vector&lt;std::string&gt; Vec;
	std::stringstream ss(Line);
	std::string Word, a;
    while(ss &gt;&gt; Word)
    Vec.push_back(Word);

	return (Pos+1 &gt; Vec.size() ? &quot;&quot; : Vec[Pos] );
}

int main()
{
	std::ifstream File;
	std::string Line;

	File.open(&quot;my_ding_ding_dong.schkriptdatay&quot;, std::ios::in);

	if(File.fail()) std::cout&lt;&lt;&quot;Nae, funzt nisch!&quot;&lt;&lt;std::endl; File.clear();

	while(!File.eof())
	{
		getline(File, Line);

		const std::string act = getWord(Line, 0);

		if((getWord(Line, 0) == &quot;b&quot;) &amp;&amp; (getWord(Line, 1) == &quot;e&quot;)) //Jup, is än befehlsnomä
		{
			std::string newLine = Line;

			unsigned short Zahl1 = convertToInt(getWord(newLine, 12);
			newLine.replace(newLine.find(&quot;,&quot;),1,&quot; &quot;);
			unsigned short Zahl2 = convertToInt(getWord(newLine, 13);
			newLine.replace(newLine.find(&quot;,&quot;),1,&quot; &quot;);
			unsigned short Zahl3 = convertToInt(getWord(newLine, 14);
			newLine.replace(newLine.find(&quot;,&quot;),1,&quot; &quot;);
			unsigned short Zahl4 = convertToInt(getWord(newLine, 15);
			newLine.replace(newLine.find(&quot;,&quot;),1,&quot; &quot;);
			unsigned short Zahl5 = convertToInt(getWord(newLine, 16);
			newLine.replace(newLine.find(&quot;,&quot;),1,&quot; &quot;);
			unsigned short Zahl6 = convertToInt(getWord(newLine, 17);
			newLine.replace(newLine.find(&quot;,&quot;),1,&quot; &quot;);
			unsigned short Zahl7 = convertToInt(getWord(newLine, 18);
		}
	}

	return 0;
}
</code></pre>
<p>Bin zu Faul zum testen, daher weiss ich nicht ob's so läuft.</p>
<p>Mfg.<br />
way</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1691379</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1691379</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Mon, 06 Apr 2009 12:28:52 GMT</pubDate></item><item><title><![CDATA[Reply to String parsen on Sun, 05 Apr 2009 18:17:36 GMT]]></title><description><![CDATA[<p>danke für die super antworten <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="🙂"
    /><br />
Durch den Boost-Artikel werde ich mich mal durchlesen, allerdings glaube ich dass das für mein (eher unkomplexes) vorhaben zu übertrieben ist....</p>
<p>Die Lösung mit den Umleitungsoperatoren erscheint mir genau perfekt für die Sache.</p>
<p>herzlichen dank</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1691390</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1691390</guid><dc:creator><![CDATA[cryps]]></dc:creator><pubDate>Sun, 05 Apr 2009 18:17:36 GMT</pubDate></item><item><title><![CDATA[Reply to String parsen on Mon, 06 Apr 2009 07:26:27 GMT]]></title><description><![CDATA[<p>lex+yacc oder flex+bison sollte nicht unerwaehnt bleiben :).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1691552</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1691552</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Mon, 06 Apr 2009 07:26:27 GMT</pubDate></item><item><title><![CDATA[Reply to String parsen on Mon, 06 Apr 2009 12:03:48 GMT]]></title><description><![CDATA[<p>hab ich jetzt was überlesen oder stand gar nicht fest ob C oder C++ weil atoi</p>
<p>way schrieb:</p>
<blockquote>
<p>float x = atoi(Num.c_str());</p>
</blockquote>
<p>ist doch C</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1691729</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1691729</guid><dc:creator><![CDATA[5cript]]></dc:creator><pubDate>Mon, 06 Apr 2009 12:03:48 GMT</pubDate></item><item><title><![CDATA[Reply to String parsen on Mon, 06 Apr 2009 12:14:00 GMT]]></title><description><![CDATA[<p>Steckt ein C in C++?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1691736</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1691736</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Mon, 06 Apr 2009 12:14:00 GMT</pubDate></item><item><title><![CDATA[Reply to String parsen on Mon, 06 Apr 2009 12:16:02 GMT]]></title><description><![CDATA[<p>knivil schrieb:</p>
<blockquote>
<p>Steckt ein C in C++?</p>
</blockquote>
<p>dazu sag ich mal nicht, denn C != C++<br />
-------------------------------------------<br />
useless postcount +1</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1691737</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1691737</guid><dc:creator><![CDATA[5cript]]></dc:creator><pubDate>Mon, 06 Apr 2009 12:16:02 GMT</pubDate></item><item><title><![CDATA[Reply to String parsen on Mon, 06 Apr 2009 12:17:30 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>wos wird desch hia... <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>
<p>Mfg.<br />
way</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1691739</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1691739</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Mon, 06 Apr 2009 12:17:30 GMT</pubDate></item><item><title><![CDATA[Reply to String parsen on Mon, 06 Apr 2009 12:24:25 GMT]]></title><description><![CDATA[<p>way schrieb:</p>
<blockquote>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;

float convertToInt(std::string Num)
{
	if((strlen(Num.c_str())) &gt; 0)
	{
		float x = atoi(Num.c_str());
		return x;
	}
	else
	{
		Num.clear();
		return 0;
	}
}
</code></pre>
</blockquote>
<p>convertToInt liefert ein float zurück? <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">int convertToInt(std::string Num) {
	int result = 0;
	if (!Num.empty()) {
		std::stringstream s(Num);
		s &gt;&gt; result;
	}
	return result;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1691742</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1691742</guid><dc:creator><![CDATA[mad_martin]]></dc:creator><pubDate>Mon, 06 Apr 2009 12:24:25 GMT</pubDate></item><item><title><![CDATA[Reply to String parsen on Mon, 06 Apr 2009 12:28:00 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Habe es vorhin auch gesehen, naja, wie gesagt, Code ist ungetestet...</p>
<p>Mfg.<br />
way</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1691745</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1691745</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Mon, 06 Apr 2009 12:28:00 GMT</pubDate></item><item><title><![CDATA[Reply to String parsen on Mon, 06 Apr 2009 12:33:42 GMT]]></title><description><![CDATA[<p>Tim06TR schrieb:</p>
<blockquote>
<p>knivil schrieb:</p>
<blockquote>
<p>Steckt ein C in C++?</p>
</blockquote>
<p>dazu sag ich mal nicht, denn C != C++</p>
</blockquote>
<p>Wer behauptet denn C == C++? Es war eine rhetorische Frage: Selbstverstaendlich steckt ein C in C++ (und das nicht nur im Bezeichner (bis auf kleine Details)).</p>
<blockquote>
<p>wos wird desch hia...</p>
</blockquote>
<p>Keine Ahnung, mal schauen ... <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/1691748</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1691748</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Mon, 06 Apr 2009 12:33:42 GMT</pubDate></item><item><title><![CDATA[Reply to String parsen on Mon, 06 Apr 2009 14:26:44 GMT]]></title><description><![CDATA[<p>knivil schrieb:</p>
<blockquote>
<p>Steckt ein C in C++?</p>
</blockquote>
<p>Da wir uns aber im C++-Forum befinden, ist sein Einwand schon berechtigt. Und <code>atoi()</code> liefert beispielsweise im Fehlerfall einfach eine Null zurück, das finde ich etwas... suboptimal.</p>
<p>Sowieso ist es mehr als sinnfrei, den <code>std::string</code> -internen <code>const char*</code> zu holen und darauf <code>strlen()</code> anzuwenden, um die Länge des Strings zu erhalten. Naja, es ist überhaupt fraglich, ob ways Code brauchbar ist. Sei es die Deklaration nicht benötigter Variablen, der Aufruf von <code>clear()</code> vor dem Verlassen des Scopes oder die hässliche Codeduplizierung. Von den restlichen Dingen einmal abgesehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1691834</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1691834</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Mon, 06 Apr 2009 14:26:44 GMT</pubDate></item></channel></rss>