The information in this article applies to:
SYMPTOMS
In a UNICODE application, CString::TrimLeft creates a string that is the
same length as the original with the first half of the trimmed string
replacing the first few characters of the original string.
CAUSEThe CString::TrimLeft function trims all leading white space characters from a string when using ASCII, which is a single-byte character set. However, when using UNICODE, which is a double-byte character set, the CString::TrimLeft function copies only half of the non-white space characters over the white spaces. In addition, because the null character is not in the first half of the non-white space characters, you end up with a new string that is a combination of the copied characters and the original string. This is due to the following line of code in STREX.CPP, which you'll find in MSVC20\MFC\SRC:
This line of code moves (nDataLength+1) bytes instead of characters.
RESOLUTION
The easiest solution is to create a global TrimLeft function to, in this
case, take a CString as a parameter. An implementation for this global
function is listed in the "Sample Code to Workaround Problem" section
below.
Both solutions will work with both single-byte and double-byte character
sets.
STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem was corrected in Visual C++ version 2.2. MORE INFORMATIONSample Code to Workaround Problem
Additional query words: 2.10 3.10 3.1
Keywords : kbcode kbnokeyword kbMFC kbVC |
Last Reviewed: January 26, 2000 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |