检查 WCHAR 是否包含字符串
check if WCHAR contains string
我有变量WCHAR sDisplayName[1024];
如何检查sDisplayName
是否包含字符串"示例"?
if(wcscmp(sDisplayName, L"example") == 0)
; //then it contains "example"
else
; //it does not
这不包括 sDisplayName
中的字符串以"example"开头或中间有"example"的情况。对于这些情况,您可以使用 wcsncmp
和 wcsstr
。
此外,此检查区分大小写。
此外,如果sDisplayName
包含垃圾,这将中断 - 即不以空结尾。
考虑改用 std::wstring。这是C++方式。
编辑:如果要匹配字符串的开头:
if(wcsncmp(sDisplayName, L"Adobe", 5) == 0)
//Starts with "Adobe"
如果要在中间找到字符串
if(wcsstr(sDisplayName, L"Adobe") != 0)
//Contains "Adobe"
请注意,如果找到字符串,wcsstr 将返回非零值,这与其余字符串不同。
您可以使用标准 C 函数的wchar_t
变体(即 wcsstr
)。
wscstr 会在 sDisplayName 中的任何位置找到你的字符串,wsccmp 会查看 sDisplayName 是否正是你的字符串。
相关文章:
- 编译包含字符串的代码时遇到问题
- 如何将包含epoch时间的十六进制字符串转换为time_t
- 一个函数,用于查找字符串1包含字符串2 c++的次数
- C++ 创建包含链表和字符串的对象的链接列表时出错
- C++-字符串是否包含一个带有简单循环的单词
- 编辑字符串以包含括号 c++ 之间的变量
- 使用提升元解析字符串解析包含的文件
- 当字符串包含 %2C 时,在 c++ 中不完整的 std::string
- C++ 检查 UTF8 字符串包含指定的字符
- 将文件作为字符串包含在内
- 为什么string.empty()在字符串包含一个值时评估为true
- boost::p rogram_option::store 在选项字符串包含混合语言字符时引发异常
- 在 c++ 中将字符串(包含字符和浮点数)转换为双精度
- 将字符串(包含数字)转换为整数并返回该整数
- 如果输入字符串包含"%",则vsntprintf_s崩溃
- 当一个字符串包含另一个字符串的一部分时比较字符串
- 如果字符串包含多个 ,如何在每25个换行符( )上分割字符串
- 输出字符串包含奇怪的字符
- 当字符串包含多个NUL字符时,如何获取c_str(用于发送)
- 乘法的字符串[包含整数],输出也存储在字符串中,如何