//=============================================================================
//
// 字数统计,一个英文字母算一个字,一个汉字算一个字,一个符号算一个字
//
//
int StatisticsANSIWordCount(const char* pText)
{
if (pText == NULL)
{
return 0;
}
// 转换为unicode
const int unicodeLen = MultiByteToWideChar(CP_ACP, 0, pText, -1, NULL, 0);
wchar_t * pUnicode = (wchar_t *)malloc((unicodeLen + 1) * sizeof(wchar_t));
memset(pUnicode, 0, (unicodeLen + 1) * sizeof(wchar_t));
MultiByteToWideChar(CP_ACP, 0, pText, -1, (LPWSTR)pUnicode, unicodeLen);
const int wordCount = wcslen(pUnicode);
int spaceCount = 0;
for (int i = 0; i < wordCount; ++i)
{
if (iswspace(pUnicode[i]))
{
++spaceCount;
}
}
free(pUnicode);
pUnicode = NULL;
return (wordCount - spaceCount);
}
字数统计,一个英文字母算一个字,一个汉字算一个字,一个符号算一个字
最新推荐文章于 2023-03-06 17:33:33 发布