GetWordCountW(LPCWSTR szText) { LPCWSTR pBuffer = szText; int lSize = lstrlenW(pBuffer); list<TCHAR> lsttext; long l, lWords = 0; WCHAR mChar; BOOL bIsCharacter = FALSE; TCHAR cEngChar = 'a'; //英文字符 TCHAR cDivChar = ' '; //分隔符 for(l = 0; l < lSize; l ++) { mChar = pBuffer[l]; if ( //英文字母、数字、拉丁文、俄文等字符定义为一个英文字母 (mChar > 0x0020 && mChar <= 0x00ff) || (mChar>= 0x0400 && mChar <= 0x04FF) //西里尔字母 || (mChar>= 0x0500 && mChar <= 0x052F) //西里尔字母补充 || (mChar>= 0x0600 && mChar <= 0x06FF) //阿拉伯文 || (mChar>= 0x0750 && mChar <= 0x077F) //阿拉伯文补充 ) { lsttext.push_back(cEngChar); } else if (mChar <= 0x0020 || mChar == '-')//其他非英文字母的英文字符定义为分隔符 { lsttext.push_back(cDivChar); } else if(mChar == 0x3000)//中文空格定义为分隔符 { lsttext.push_back(cDivChar); } else//非英文字母以及分隔符的字符代表一个字 { lsttext.push_back(cDivChar); lsttext.push_back(cEngChar); lsttext.push_back(cDivChar); } } lsttext.push_back(cDivChar); TCHAR c; list<TCHAR>::iterator iter = lsttext.begin(); for(;iter != lsttext.end(); iter++) { c = *iter; if(bIsCharacter && c != cEngChar) { bIsCharacter = FALSE; lWords ++; } else if(c == cEngChar) { bIsCharacter = TRUE; continue; } } lsttext.clear(); return lWords; }