I ran into this problem recently when debugging some native code and thought that it will be good to share this with everyone . CString sampleString = CString(_T( "Sample\0String" ), 14); int len = sampleString.GetLength(); // len is 14 CString trimmedString