判断WCHAR字符串是否为guid
时间: 2023-10-16 18:12:04 浏览: 47
可以使用Windows API中的CLSIDFromString函数来判断WCHAR字符串是否为GUID。如果函数返回S_OK,则说明该字符串是GUID格式,否则不是。
示例代码:
```c++
#include <windows.h>
bool IsGuid(const wchar_t* str)
{
GUID guid;
return SUCCEEDED(CLSIDFromString(str, &guid));
}
```
相关问题
c 判断unicode字符串是否为数字
可以使用 Unicode 字符集中数字字符的范围来判断一个 Unicode 字符串是否为数字。在 Unicode 字符集中,数字字符的范围是 U+0030 到 U+0039,U+0660 到 U+0669,U+06F0 到 U+06F9,U+07C0 到 U+07C9,U+0966 到 U+096F,U+09E6 到 U+09EF,U+0A66 到 U+0A6F,U+0AE6 到 U+0AEF,U+0B66 到 U+0B6F,U+0BE6 到 U+0BEF,U+0C66 到 U+0C6F,U+0CE6 到 U+0CEF,U+0D66 到 U+0D6F,U+0DE6 到 U+0DEF,U+0E50 到 U+0E59,U+0ED0 到 U+0ED9,U+0F20 到 U+0F29。
以下是一个示例代码,用于判断一个 Unicode 字符串是否为数字:
```c
#include <stdio.h>
#include <wchar.h>
int is_unicode_digit(const wchar_t *str) {
while (*str) {
wchar_t ch = *str;
if (ch < 0x0030 || (ch > 0x0039 && ch < 0x0660) || (ch > 0x0669 && ch < 0x06F0) ||
(ch > 0x06F9 && ch < 0x07C0) || (ch > 0x07C9 && ch < 0x0966) || (ch > 0x096F && ch < 0x09E6) ||
(ch > 0x09EF && ch < 0x0A66) || (ch > 0x0A6F && ch < 0x0AE6) || (ch > 0x0AEF && ch < 0x0B66) ||
(ch > 0x0B6F && ch < 0x0BE6) || (ch > 0x0BEF && ch < 0x0C66) || (ch > 0x0C6F && ch < 0x0CE6) ||
(ch > 0x0CEF && ch < 0x0D66) || (ch > 0x0D6F && ch < 0x0DE6) || (ch > 0x0DEF && ch < 0x0E50) ||
(ch > 0x0E59 && ch < 0x0ED0) || (ch > 0x0ED9 && ch < 0x0F20) || ch > 0x0F29) {
return 0;
}
str++;
}
return 1;
}
int main() {
const wchar_t *str1 = L"1234";
const wchar_t *str2 = L"12.34";
const wchar_t *str3 = L"一二三四";
const wchar_t *str4 = L"1二3四";
printf("%ls is %s digit\n", str1, is_unicode_digit(str1) ? "a" : "not a");
printf("%ls is %s digit\n", str2, is_unicode_digit(str2) ? "a" : "not a");
printf("%ls is %s digit\n", str3, is_unicode_digit(str3) ? "a" : "not a");
printf("%ls is %s digit\n", str4, is_unicode_digit(str4) ? "a" : "not a");
return 0;
}
```
输出结果为:
```
1234 is a digit
12.34 is not a digit
一二三四 is not a digit
1二3四 is not a digit
```
如何判定wchar字符串中是否包含/exe关键字
可以使用标准库函数`wcsstr()`在`wchar`字符串中查找子字符串。具体实现可以参考以下代码:
```c++
#include <iostream>
#include <cwchar>
int main() {
const wchar_t* str = L"Hello, world! This is an example string containing the /exe keyword.";
const wchar_t* keyword = L"/exe";
if (wcsstr(str, keyword) != NULL) {
std::wcout << L"The string contains the /exe keyword." << std::endl;
} else {
std::wcout << L"The string does not contain the /exe keyword." << std::endl;
}
return 0;
}
```
需要注意的是,`wchar_t`字符串需要以`L`开头表示为宽字符类型,而不是普通的`char`字符串。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![flv](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)