A function written by yourself.
If the string contains Chinese, simple interception will appear garbled, simple practice is to convert it first to wide characters and then take it back, turn it back. Of course, for the procedure of Unicode, it is directly intercepted, and it is not necessary to convert.
///
Bool truncstringleft (odtstr lpszsource, int ncnt) {atlassert (lpszsource); if (null == lpszsource || NCNT <1 ||! Lpszsource [0]) Return False;
WCHAR wszWide [MAX_PATH * 2]; # ifdef UNICODE _tcscpy (wszWide, lpszSource); # else MultiByteToWideChar (CP_ACP, 0, lpszSource, -1, wszWide, ARRAYSIZE (wszWide)); #endif if (wcslen (wszWide)> nCnt) WSZWIDE [NCNT] = 0;
#ifdef unicode _tcscpy (lpszsource, wszwide); # else widechartomultibyte (CP_ACP, 0, WSZWIDE, -1, LPSZSSOURCE, MAX_PATH, NULL, NULL); # ENDIF
Return True;}
///
Some related discussions: http: //dev.9cbs.net/develop/Article/66/66387.shtmhttp: //community.9cbs.net/expert/topic/3906/3906053.xml? Temp = .4827692