How do I keep percent signs (%) copying from LPCTSTR to LPTSTR?

123 Views Asked by At

I am a beginner in this and after a lot of frustration I finally had the courage to ask to all of you, the true professionals.

I need to keep all the percent signs (%) I receive from a LPCTSTR when I copy it to a LPTSTR. After some researching and trying, I came with this:

LPCTSTR lpRemapping; // Contains a string with percents (%) in it
size_t nSize = _tcsclen(lpRemapping) + 1;
LPTSTR lpBuffer = new TCHAR[nSize];
errno_t nResult = _tcsncpy_s(lpBuffer, nSize, lpRemapping, ((size_t)-1));
for (int currentChar = 0; currentChar < nSize; currentChar++) {
    if (lpRemapping[currentChar] == '%') {
        lpBuffer[currentChar] = '%%';
    }
}

But it seems I am still losing the percent signs in the process. I have read a lot of answers telling me to use %% but I am doing something wrong here and I don't know what it is.

I do not control the string I am receiving and some of them will definitely contain the percent sign (%).

I really appreciate your time and I hope you can bring me some light in this matter.

0

There are 0 best solutions below