gpt4 book ai didi

c++ - 检测字符串中的 Unicode 字符

转载 作者:搜寻专家 更新时间:2023-10-31 01:44:43 25 4
gpt4 key购买 nike

我有字符串输入。我想检查所有字符并提示用户输入字符串中是否有任何 Unicode 字符。

如何在 C++ 中执行此验证。

例如。在记事本中,如果您输入任何 Unicode 字符并尝试使用 ANSI 编码保存它,它会提示有关 Unicode 字符。我想做类似的验证。

最佳答案

您可以使用 IsTextUnicode 函数。据我所知,这是记事本使用的功能。

MSDN 链接: http://msdn.microsoft.com/en-us/library/windows/desktop/dd318672%28v=vs.85%29.aspx

只需插入 NULL 作为最后一个参数。

#include <string>
#include <Windows.h>

int main()
{
std::string s = "Hallo!";
std::wstring ws = L"Hello!";

if (::IsTextUnicode(ws.c_str(), ws.length(), NULL) == 1)
{
// is unicode
int i = 0;
}
else
{
// no unicode
int i = 1;
}

return 0;
}

关于c++ - 检测字符串中的 Unicode 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23082819/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com