How can I replace string in a wchar_t variable?
wchar_t text[] = L"Start Notepad.exe";
I want to replace Notepad.exe with Word.exe.
wchar_t is just one character, not the string. In your case you need std::wstring, string consisting of wchar_t. Here is answer on how to replace one substring with another.
Basically you need to use a pointer or index variable and replace the characters one by one and end with the null character.
Here is an example, (note that C++ programmers might hate this code, but is fairly acceptable for C programmers...):
wchar_t lpSrcText[] = L"Start Notepad.exe";
wchar_t const * lpReplace = L"Word.exe";
int i = 0;
while(*(lpReplace + i))
{
lpSrcText[6 + i] = *(lpReplace + i);
i++;
}
*(lpReplace + i) = L'\0';
std::wstring.wchar_t*then you can pass&text[0]like:winfunc(&text[0], text.size());&text[0]and passing the address of awchar_tarray. In fact thestd::wstringclass is basically just a wrapper around a dynamicwchar_t*array.std::wstringmethods are trivial, inlined and calling them is optimized away by the compiler. Its just as fast as an array (because that's what it is).