Use Unicode-ANSI to translate, break down strings, find Chinese characters in the string (wide character)

xiaoxiao2021-03-06  18

Seeing a lot of netizens decomposing strings to find Chinese characters (Japanese children ...) used by comparison characters, doing, but there are two problems: 1 must know the starting value of Chinese characters, 2 When there is simple Chinese, Traditional Chinese, Japanese or more mixed is difficult to judge.

The way I use is to find a wide character with Unicode-ANSI conversion.

Description: We can use Unicode and ANSI to find Chinese characters in strings: a Chinese character, Latin alphabet or number accounts for a character in Unicode (Wchar), and Chinese characters in ANSI (Char) account for 2 characters, and Latin letters or numbers account for a character, using this, you can break down Chinese characters (wide characters).

//testing method

void CTestDlg :: OnButton1 () {CString aa = "9494858 are accounted for in a character ?? acx"; CString strMulti, strWide; InterceptString (aa, strMulti, strWide); AfxMessageBox (strMulti); AfxMessageBox (strWide);}

// strSource: the source string // strMultiChar: the multi string // strWideChar: the Wide stringBOOL CTestDlg :: InterceptString (CString strSource, CString & strMultiChar, CString & strWideChar) {strMultiChar = ""; strWideChar = "";

STRSOURCE.trimLEFT (); strsource.trimright (); int NLENGTH = strsource.getLength (); // Create a wide-byte string pointer to Unicode Form LPWSTR LPWSZWIDE = New Wchar [NLENGTH 1]; ZeroMemory (lpwszWide, (nLength 1) * sizeof (WCHAR)); # ifdef UNICODE wcscpy (lpwszWide, strSource); # else MultiByteToWideChar (CP_ACP, 0, strSource, nLength 1, lpwszWide, nLength 1); # endif

Int nwidelen = WCSLEN (LPWSZWIDE); Wchar WSZTEMP [2]; char sztemp [3];

// Test each Unicode character, convert the character into ansi form / / Depending on the length of whether it is Chinese characters (Japan ...) for (int i = 0; i

转载请注明原文地址:https://www.9cbs.com/read-41353.html

New Post(0)