<?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[PLZ aus String mit string.find()]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>ich habe mir schon aus einem großen Datensatz(einer txt) einen Substring rausgeholt. Es ist ein Adresse, die nun wie folgt aussieht:</p>
<p>Lobdengaustraße 13 69493 Hirschberg</p>
<p>Nun möchte mir daraus noch die PLZ rausholen, am besten auch mit string.find().<br />
Ich hab überlegt, ob man das mit regulären Ausdrücken machen kann, weiß diese aber mit string.find() nicht richtig einzusetzen bzw hab keine Ahnung wie das geht.<br />
Ich muss also irgendwie eine 5stellige Zahl suchen, die am Anfang und am Ende von Leerzeichen umgeben sind.</p>
<p>Was habt ihr für Vorschläge und Lösungen?</p>
<p>PS: Bin noch blutiger Anfänger, deshalb erklärt es mir bitte sehr genau ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/314310/plz-aus-string-mit-string-find</link><generator>RSS for Node</generator><lastBuildDate>Sat, 01 Aug 2026 08:55:11 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/314310.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 27 Feb 2013 08:04:02 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to PLZ aus String mit string.find() on Wed, 27 Feb 2013 08:04:02 GMT]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>ich habe mir schon aus einem großen Datensatz(einer txt) einen Substring rausgeholt. Es ist ein Adresse, die nun wie folgt aussieht:</p>
<p>Lobdengaustraße 13 69493 Hirschberg</p>
<p>Nun möchte mir daraus noch die PLZ rausholen, am besten auch mit string.find().<br />
Ich hab überlegt, ob man das mit regulären Ausdrücken machen kann, weiß diese aber mit string.find() nicht richtig einzusetzen bzw hab keine Ahnung wie das geht.<br />
Ich muss also irgendwie eine 5stellige Zahl suchen, die am Anfang und am Ende von Leerzeichen umgeben sind.</p>
<p>Was habt ihr für Vorschläge und Lösungen?</p>
<p>PS: Bin noch blutiger Anfänger, deshalb erklärt es mir bitte sehr genau ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302424</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302424</guid><dc:creator><![CDATA[Kalif]]></dc:creator><pubDate>Wed, 27 Feb 2013 08:04:02 GMT</pubDate></item><item><title><![CDATA[Reply to PLZ aus String mit string.find() on Wed, 27 Feb 2013 08:14:07 GMT]]></title><description><![CDATA[<p>Wenn deine Addresszeilen immer genau dieses Format haben, dann geht das hier:</p>
<pre><code>struct Address
{
	std::string street;
	unsigned int number;
	std::string city;
	int postalcode; // vllt besser string oder sowas
};

Address getAdress(std::string const&amp; line)
{
	std::stringstream ss;
	ss &lt;&lt; line;

	Address ad;

	ss &gt;&gt; ad.street &gt;&gt; ad.number &gt;&gt; ad.postalcode &gt;&gt; ad.city;

	return ad;
}

int main()
{
	Address a = getAddress(&quot; Lobdengaustraße 13    69493 Hirschberg  &quot;);

	return 0;
}
</code></pre>
<p>(ungetestet)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302426</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302426</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Wed, 27 Feb 2013 08:14:07 GMT</pubDate></item><item><title><![CDATA[Reply to PLZ aus String mit string.find() on Wed, 27 Feb 2013 08:24:15 GMT]]></title><description><![CDATA[<p>Größtenteils schon, aber nicht immer</p>
<p>Kannst du mal bitte erklären, was da passiert?</p>
<p>Nochmal: Ich möchte mir nur die PLZ aus diesem String rausholen, quasi einen Substring in dem nur die 5 Zahlen drin stehen. Dies sollte allgemeingültig sein und nicht nur passend für das genannte Beispiel.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302428</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302428</guid><dc:creator><![CDATA[Kalif]]></dc:creator><pubDate>Wed, 27 Feb 2013 08:24:15 GMT</pubDate></item><item><title><![CDATA[Reply to PLZ aus String mit string.find() on Wed, 27 Feb 2013 08:26:51 GMT]]></title><description><![CDATA[<p>muss da unten nicht</p>
<p>Address ad = getAddress(...)</p>
<p>anstatt</p>
<p>Address a = getAdress(..)</p>
<p>stehen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302431</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302431</guid><dc:creator><![CDATA[Kalif]]></dc:creator><pubDate>Wed, 27 Feb 2013 08:26:51 GMT</pubDate></item><item><title><![CDATA[Reply to PLZ aus String mit string.find() on Wed, 27 Feb 2013 08:29:37 GMT]]></title><description><![CDATA[<p>Kalif schrieb:</p>
<blockquote>
<p>Dies sollte allgemeingültig sein und nicht nur passend für das genannte Beispiel.</p>
</blockquote>
<p>geht nicht. Du musst schon wissen, in welchen möglichen Formaten die Eingabedaten vorliegen.</p>
<p>Höchstwahrscheinlich musst du da mit einem regulären Ausdruck ran, da solltest du dir mal boost::regex ansehen. Wenn vor und nach der (fünfstelligen, nummerischen) Postleitzahl immer ein Leerzeichen steht, hast du schonmal gute Chancen, diese rauszufiltern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302432</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302432</guid><dc:creator><![CDATA[daddy_felix]]></dc:creator><pubDate>Wed, 27 Feb 2013 08:29:37 GMT</pubDate></item><item><title><![CDATA[Reply to PLZ aus String mit string.find() on Wed, 27 Feb 2013 08:29:48 GMT]]></title><description><![CDATA[<p>und wie kann ich nach deiner Lösung nun die PLZ ausgeben?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302433</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302433</guid><dc:creator><![CDATA[Kalif]]></dc:creator><pubDate>Wed, 27 Feb 2013 08:29:48 GMT</pubDate></item><item><title><![CDATA[Reply to PLZ aus String mit string.find() on Wed, 27 Feb 2013 08:44:59 GMT]]></title><description><![CDATA[<p>Kalif schrieb:</p>
<blockquote>
<p>muss da unten nicht</p>
<p>Address ad = getAddress(...)</p>
<p>anstatt</p>
<p>Address a = getAdress(..)</p>
<p>stehen?</p>
</blockquote>
<p>ja, müsste es. das ist ein - in diesem Kontext - völlig irrelevanter Tippfehler. Deswegen stand da ja auch &quot;ungetestet&quot; was soviel heißt wie &quot;ich habe es nicht kompiliert, aber vom Prinzip sollte es so funktionieren&quot;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302434</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302434</guid><dc:creator><![CDATA[daddy_felix]]></dc:creator><pubDate>Wed, 27 Feb 2013 08:44:59 GMT</pubDate></item><item><title><![CDATA[Reply to PLZ aus String mit string.find() on Wed, 27 Feb 2013 08:31:35 GMT]]></title><description><![CDATA[<p>Ja, davor und danach stehen im Leerzeichen</p>
<p>was kann ich mit boost::regex machen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302435</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302435</guid><dc:creator><![CDATA[Kalif]]></dc:creator><pubDate>Wed, 27 Feb 2013 08:31:35 GMT</pubDate></item><item><title><![CDATA[Reply to PLZ aus String mit string.find() on Wed, 27 Feb 2013 08:43:32 GMT]]></title><description><![CDATA[<p>Kalif schrieb:</p>
<blockquote>
<p>was kann ich mit boost::regex machen?</p>
</blockquote>
<p>strings mit Hilfe regulärer Ausdrücke auseinandernehmen. Wenn du C++11 benutzen kannst, geht das sogar ohne boost:</p>
<pre><code class="language-cpp">#include &lt;regex&gt;
#include &lt;iostream&gt;

int main()
{
    const std::string s = &quot;/home/toto/FILE_mysymbol_EVENT.DAT&quot;;
    std::regex rgx(&quot;.*FILE_(\\w+)_EVENT\\.DAT.*&quot;);
    std::smatch match;

    if (std::regex_search(s.begin(), s.end(), match, rgx))
        std::cout &lt;&lt; &quot;match: &quot; &lt;&lt; match[1] &lt;&lt; '\n';
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2302438</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302438</guid><dc:creator><![CDATA[daddy_felix]]></dc:creator><pubDate>Wed, 27 Feb 2013 08:43:32 GMT</pubDate></item><item><title><![CDATA[Reply to PLZ aus String mit string.find() on Wed, 27 Feb 2013 08:45:32 GMT]]></title><description><![CDATA[<p>edit: sorry, &quot;zitieren&quot; statt &quot;editieren&quot; geklickt. Ist wohl doch noch zu früh...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302439</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302439</guid><dc:creator><![CDATA[daddy_felix]]></dc:creator><pubDate>Wed, 27 Feb 2013 08:45:32 GMT</pubDate></item><item><title><![CDATA[Reply to PLZ aus String mit string.find() on Wed, 27 Feb 2013 08:46:18 GMT]]></title><description><![CDATA[<p>sorry, aber ich verstehe gar nicht was da steht</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302441</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302441</guid><dc:creator><![CDATA[Kalif]]></dc:creator><pubDate>Wed, 27 Feb 2013 08:46:18 GMT</pubDate></item><item><title><![CDATA[Reply to PLZ aus String mit string.find() on Wed, 27 Feb 2013 08:48:00 GMT]]></title><description><![CDATA[<p>Kalif schrieb:</p>
<blockquote>
<p>sorry, aber ich verstehe gar nicht was da steht</p>
</blockquote>
<p>dann schau dir erstmal reguläre Ausdrücke an.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302443</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302443</guid><dc:creator><![CDATA[daddy_felix]]></dc:creator><pubDate>Wed, 27 Feb 2013 08:48:00 GMT</pubDate></item><item><title><![CDATA[Reply to PLZ aus String mit string.find() on Wed, 27 Feb 2013 08:52:22 GMT]]></title><description><![CDATA[<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;sstream&gt;
using namespace std;
struct Address
{
	std::string street;
	unsigned int number;
	std::string city;
	int postalcode; // vllt besser string oder sowas
};

Address getAdress(std::string const&amp; line)
{
	std::stringstream ss;
	ss &lt;&lt; line;

	Address ad;

	ss &gt;&gt; ad.street &gt;&gt; ad.number &gt;&gt; ad.postalcode &gt;&gt; ad.city;

	return ad;
}

int main()
{
	Address a = getAddress(&quot; Lobdengaustraße 13    69493 Hirschberg  &quot;);
	cout &lt;&lt; a.postalcode;
	return 0;
}
</code></pre>
<p>Wo liegts Problem?</p>
<p>daddy_felix schrieb:</p>
<blockquote>
<pre><code class="language-cpp">int main()
{
    const std::string s = &quot;/home/toto/FILE_mysymbol_EVENT.DAT&quot;;
    std::regex rgx(&quot;.*FILE_(\\w+)_EVENT\\.DAT.*&quot;);
    std::smatch match;

    if (std::regex_search(s.begin(), s.end(), match, rgx))
        std::cout &lt;&lt; &quot;match: &quot; &lt;&lt; match[1] &lt;&lt; '\n';
}
</code></pre>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302445</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302445</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Wed, 27 Feb 2013 08:52:22 GMT</pubDate></item><item><title><![CDATA[Reply to PLZ aus String mit string.find() on Wed, 27 Feb 2013 08:53:18 GMT]]></title><description><![CDATA[<p>Also:</p>
<p>Erstens:</p>
<p>daddy_felix schrieb:</p>
<blockquote>
<p>Kalif schrieb:</p>
<blockquote>
<p>muss da unten nicht</p>
<p>Address ad = getAddress(...)</p>
<p>anstatt</p>
<p>Address a = getAdress(..)</p>
<p>stehen?</p>
</blockquote>
<p>ja, müsste es. das ist ein - in diesem Kontext - völlig irrelevanter Tippfehler. Deswegen stand da ja auch &quot;ungetestet&quot; was soviel heißt wie &quot;ich habe es nicht kompiliert, aber vom Prinzip sollte es so funktionieren&quot;.</p>
</blockquote>
<p>Nein muss es nicht. Es wird eine lokale Variable per Kopie zurückgegeben, der Name der neuen Variable ist vollkommen irrelevant, unvorhersehbar und letztlich auch nichtmals nötig (Temporärer Wert, RValue...)<br />
Das müsstest du als professioneller Software-Entwickler eigentlich wissen, felix ;). Aber egal, passt alles...</p>
<p>Zweitens:</p>
<p>Kalif schrieb:</p>
<blockquote>
<p>und wie kann ich nach deiner Lösung nun die PLZ ausgeben?</p>
</blockquote>
<p>Alleine diese Antwor bzw Frage besagt doch schon, dass Khalif keinerlei Ahnung vom Programmieren bzw C++ hat. Was du jetzt nämlich nur noch brauchst, ist der Memberzugriff über das Address-struct-Objekt auf die PLZ.</p>
<pre><code>std::string plz = boost::lexical_cast&lt;std::string&gt;(a.postalcode);
</code></pre>
<p>Da haste aus nem int auch den String...</p>
<p>Damit komme ich zu Drittens:<br />
Die Lösung die daddy_felix gepostet hat, zeigt nur die Vorgehensweise der Regex (wobei ich ehrlich zugeben muss, dass ich Regex nicht kann) und ist keine Lösung für dieses Beispiel.</p>
<p>Mein Tipp (und wahrscheinlich auch der Tipp von vielen anderne hier im Forum): Nimm dir ein gutes Buch und lern C++, wenn dir was dran liegt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302446</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302446</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Wed, 27 Feb 2013 08:53:18 GMT</pubDate></item><item><title><![CDATA[Reply to PLZ aus String mit string.find() on Wed, 27 Feb 2013 09:03:09 GMT]]></title><description><![CDATA[<p>Tut mir Leid Jungs, dass ich hier vllt zur Belustigung beitrage, aber ich bin eigentlich gar kein Programmierer. Ich hab C++ mal in der Schule gelernt, aber nicht wirklich tiefgründig.<br />
Und nun musste ich im Praktikum gleich was programmieren, obwohl ich ausdrücklich meinte, dass mir das nicht liegt. Also Augen zu und durch.<br />
Ich bin eigentlich eher Wirtschaftsinformatiker.</p>
<p>Trotzdem danke für eure Hilfe und Geduld ^^, ich habe es hinbekommen!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302451</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302451</guid><dc:creator><![CDATA[Kalif]]></dc:creator><pubDate>Wed, 27 Feb 2013 09:03:09 GMT</pubDate></item><item><title><![CDATA[Reply to PLZ aus String mit string.find() on Wed, 27 Feb 2013 09:14:01 GMT]]></title><description><![CDATA[<p>Wirtschaftsinformatiker ?</p>
<blockquote>
<p>...lernt man im Wirtschaftsinformatik Studium von beiden Bereichen gerade so viel, dass man weder mit dem Computer, noch mit dem &quot;Abacus&quot; umgehen kann. <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>
</blockquote>
<p>Aber was ist denn ein &quot;Eher Wirtschaftsinformatiker&quot; ? <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="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302454</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302454</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Wed, 27 Feb 2013 09:14:01 GMT</pubDate></item><item><title><![CDATA[Reply to PLZ aus String mit string.find() on Wed, 27 Feb 2013 10:20:07 GMT]]></title><description><![CDATA[<p>out schrieb:</p>
<blockquote>
<p>Wo liegts Problem?</p>
</blockquote>
<p>1. kompiliert nicht<br />
2. Dass der Eingabestring wohl auch mal komplett anders aussehen kann. Oder auch nur ien bisschen - wie genau, hat Kalif ja leider nicht verraten. Aber die folgenden Strings funktionieren shconmal nicht:</p>
<p>&quot; Lobdengaustraße 13a 69493 Hirschberg &quot;<br />
&quot; Roter Weg 13 69493 Hirschberg &quot;</p>
<p>out schrieb:</p>
<blockquote>
<p>daddy_felix schrieb:</p>
<blockquote>
<pre><code class="language-cpp">int main()
{
    const std::string s = &quot;/home/toto/FILE_mysymbol_EVENT.DAT&quot;;
    std::regex rgx(&quot;.*FILE_(\\w+)_EVENT\\.DAT.*&quot;);
    std::smatch match;

    if (std::regex_search(s.begin(), s.end(), match, rgx))
        std::cout &lt;&lt; &quot;match: &quot; &lt;&lt; match[1] &lt;&lt; '\n';
}
</code></pre>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
</blockquote>
<p>was ist denn damit? Zugegeben, ich habe den Schnipsel aus dem Netz kopiert und da ich (noch) nicht mit C++11 arbeiten kann, kann ich die Qualität auch nciht beurteilen. Aber auf den ersten Blick sah es jetzt nicht soo schlecht aus...</p>
<p>Skym0sh0 schrieb:</p>
<blockquote>
<p>Nein muss es nicht. Es wird eine lokale Variable per Kopie zurückgegeben, der Name der neuen Variable ist vollkommen irrelevant, unvorhersehbar und letztlich auch nichtmals nötig (Temporärer Wert, RValue...)<br />
Das müsstest du als professioneller Software-Entwickler eigentlich wissen, felix ;). Aber egal, passt alles...</p>
</blockquote>
<p>als professioneller Softwareentwickler weiß ich, dass man eine Funktion mit dem Namen &quot;getAdress&quot; nicht aufrufen kann, indem man &quot;getAddress&quot; tippt <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/2302482</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302482</guid><dc:creator><![CDATA[daddy_felix]]></dc:creator><pubDate>Wed, 27 Feb 2013 10:20:07 GMT</pubDate></item><item><title><![CDATA[Reply to PLZ aus String mit string.find() on Wed, 27 Feb 2013 10:32:52 GMT]]></title><description><![CDATA[<p>Wie gesagt, ungetestet im Notepad runtergetippt, sämtliche Includes und namespaces weggelassen. Ist halt nervig, dass die doofen Engländer Address nicht wie im Deutschen mit einem D schreiben.</p>
<p>They do not want the D. <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="😉"
    /> *if you know what i mean<a href="http://media.comicvine.com/uploads/12/121530/2790387-IF-you-know-what-i-mean.png" rel="nofollow">*</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302485</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302485</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Wed, 27 Feb 2013 10:32:52 GMT</pubDate></item></channel></rss>