U++ framework
Do not panic. Ask here before giving up.

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: 14291
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 May 30 21:24:56 GMT+2 2026

Total time taken to generate the page: 0.00609 seconds