I know CString has a powful method Replace(), is there any similiar
method for replacement in tstring?

My problem is I got a TCHAR[] in my code, and I need to replace a
substring of it. It seems I should use tstring, but I didn't find any
Replace() method in tstring...


Thanks

Re: How to replace a substring in TCHAR[] or tstring? by Igor

Igor
Thu Jun 21 20:31:38 CDT 2007

"Carol" <Carol.Hu.Mail@gmail.com> wrote in message
news:1182474538.100938.224240@d30g2000prg.googlegroups.com
> I know CString has a powful method Replace(), is there any similiar
> method for replacement in tstring?

replace()
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



Re: How to replace a substring in TCHAR[] or tstring? by Mateusz

Mateusz
Thu Jun 21 21:32:38 CDT 2007

On Fri, 22 Jun 2007 03:08:58 +0200, Carol <Carol.Hu.Mail@gmail.com> wrote:
> I know CString has a powful method Replace(), is there any similiar
> method for replacement in tstring?
>
> My problem is I got a TCHAR[] in my code, and I need to replace a
> substring of it. It seems I should use tstring, but I didn't find any
> Replace() method in tstring...

I'm not sure what you mean as tstring but here is my version
based on the standart string tempalate:

#include <iostream>
#include <string>
#include <tchar.h>

typedef std::basic_string<TCHAR, std::char_traits<TCHAR>,
std::allocator<TCHAR> > tstring;

int main()
{
tstring s(_T("abcdef"));
s.replace(s.find(_T("cd")), 2, _T("12"));

std::wcout << s << std::endl;
return 0;
}

Cheers
--
Mateusz Loskot
http://mateusz.loskot.net