Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » no String::Replace() ?
Re: no String::Replace() ? [message #29210 is a reply to message #29147] Sun, 10 October 2010 20:01 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14266
Registered: November 2005
Ultimate Member
OK, based on public request, I started inspired with Koldo's code and here is what I have added to String:

template <class B>
void AString<B>::Replace(const tchar *find, int findlen, const tchar *replace, int replacelen)
{
	String r;
	int i = 0;
	const tchar *p = Begin();
	for(;;) {
		int j = Find(findlen, find, i);
		if(j < 0)
			break;
		r.Cat(p + i, j - i);
		r.Cat(replace, replacelen);
		i = j + findlen;
	}
	r.Cat(p + i, GetCount() - i);
	*this = r;
}


Please check the algo...

There are also

	void   Replace(const String& find, const String& replace) { Replace(~find, find.GetCount(), ~replace, replace.GetCount()); }
	void   Replace(const tchar *find, const tchar *replace)   { Replace(find, strlen(find), replace, strlen(replace)); }

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Compile errror in ctrllib/update.cpp
Next Topic: PROPOSAL: SerializeStore helper
Goto Forum:
  


Current Time: Sat Jul 19 05:05:13 CEST 2025

Total time taken to generate the page: 0.03714 seconds