<?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[Zeichen löschen in einem String]]></title><description><![CDATA[<p>Hallo ich möchte bestimmte Zeichen löschen in einem String bestimmte Zeichen dienen als Seperationszeichen und dürfen von dem User nicht benutzt werden. Habe nun eine Fkt geschrieben die dies tut könnt ihr mal drüber gugn bzw Tipps geben für Optimierung welche der beiden Funktionen ist performanter ?</p>
<pre><code>string&amp; deleteCharacter(string &amp;s, char del) {
	if( s.empty() )
		return s;

	string::iterator i , j;
	i = j = s.begin();

	for( i,j ; i != s.end() ; i++ ) {
		if( *i == del ) { 
			continue;
		}
		*j = *i;
		j++;
	}
	*j = 0;
	s = s.c_str();

	return s;
}

string&amp; deleteChar(string &amp;s, char del) {
	if( s.empty() )
		return s;

	char *tmp = new char[s.size()+1];
	strcpy(tmp,s.c_str());
	unsigned int i, j;

	for( i = 0, j = 0 ; tmp[i] != 0 ; i++ ) {
		if( tmp[i] != del ) {
			tmp[j++] = tmp[i];
		}
	}
	tmp[j] = 0;
	s = tmp;
	return s;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/322011/zeichen-löschen-in-einem-string</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Jul 2026 13:53:10 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/322011.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 03 Dec 2013 09:58:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Zeichen löschen in einem String on Tue, 03 Dec 2013 09:58:36 GMT]]></title><description><![CDATA[<p>Hallo ich möchte bestimmte Zeichen löschen in einem String bestimmte Zeichen dienen als Seperationszeichen und dürfen von dem User nicht benutzt werden. Habe nun eine Fkt geschrieben die dies tut könnt ihr mal drüber gugn bzw Tipps geben für Optimierung welche der beiden Funktionen ist performanter ?</p>
<pre><code>string&amp; deleteCharacter(string &amp;s, char del) {
	if( s.empty() )
		return s;

	string::iterator i , j;
	i = j = s.begin();

	for( i,j ; i != s.end() ; i++ ) {
		if( *i == del ) { 
			continue;
		}
		*j = *i;
		j++;
	}
	*j = 0;
	s = s.c_str();

	return s;
}

string&amp; deleteChar(string &amp;s, char del) {
	if( s.empty() )
		return s;

	char *tmp = new char[s.size()+1];
	strcpy(tmp,s.c_str());
	unsigned int i, j;

	for( i = 0, j = 0 ; tmp[i] != 0 ; i++ ) {
		if( tmp[i] != del ) {
			tmp[j++] = tmp[i];
		}
	}
	tmp[j] = 0;
	s = tmp;
	return s;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2369505</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369505</guid><dc:creator><![CDATA[Pisa-Test]]></dc:creator><pubDate>Tue, 03 Dec 2013 09:58:36 GMT</pubDate></item><item><title><![CDATA[Reply to Zeichen löschen in einem String on Tue, 03 Dec 2013 10:02:10 GMT]]></title><description><![CDATA[<pre><code>string&amp; deleteCharacter(string &amp;s, char del) {
	if( s.empty() )
		return s;

	string::iterator i , j;
	i = j = s.begin();

	for( i,j ; i != s.end() ; i++ ) {
		if( *i != del ) { 
			*j++ = *i;
		}
	}

	*j = 0;
	s = s.c_str();
	return s;
}
</code></pre>
<p>die erste durch das hier ersetzen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369506</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369506</guid><dc:creator><![CDATA[Pisa-Test]]></dc:creator><pubDate>Tue, 03 Dec 2013 10:02:10 GMT</pubDate></item><item><title><![CDATA[Reply to Zeichen löschen in einem String on Tue, 03 Dec 2013 10:15:30 GMT]]></title><description><![CDATA[<p>std::remove_if und std::erase/string::resize ist wahrscheinlich ein eck schneller.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369507</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369507</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Tue, 03 Dec 2013 10:15:30 GMT</pubDate></item><item><title><![CDATA[Reply to Zeichen löschen in einem String on Tue, 03 Dec 2013 10:18:12 GMT]]></title><description><![CDATA[<pre><code>std::string str = &quot;kdhsgjksdgnksdkgjsdkgjnsdkögjnda&lt;köfgjnargh&lt;dfjklgvbipuw4t&lt;hib&quot;;
char c = 's';
str.erase(std::remove(str.begin(), str.end(), c), str.end());
</code></pre>
<p>edit: zu langsam <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369508</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369508</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Tue, 03 Dec 2013 10:18:12 GMT</pubDate></item></channel></rss>