
How to trim a string in a _variant_t
Quote:
> _variant_t vnt = recordset->Item[1]->Value;
> <ytour favorite string wrapper> str = V_BSTR(&vnt);
> <trim, convert etc using your favorite class>
> or
> _variant_t vnt = recordset->Item[1]->Value;
> wcscpy(wszBuffer, V_BSTR(&vnt));
> <manipulate using the C RTL wcsXXX functions>
But how do you manipulate a wstring (wchar_t?) string character by
character? When using a standard single-byte char string in C++ my RTrim()
function would look something like:
// Removes ending spaces in string
void RTrim(char *lpzString)
{
int iOffset = strlen(lpzString);
// Scan for the first non-space character in string from the end and
backwards
for(; *(lpzString + iOffset) != ' ' || iOffset > 0; iOffset--);
// Null terminate string
*( lpzString + iOffset + 1) = NULL;
Quote:
}
You get the point..
How would you do the same with a wstring (or wchar_t, multibyte-strings)?
_bstr_t strings don't use NULL characters and in Unicode-strings every
characters occupies two bytes and so on..
// jP