如何使用 c++ win32 API 拆分字符
How to split character using c++ win32 Api?
我正在使用c ++ win32 api。
我想使用 delimiter
拆分角色。
那个角色像"CN=USERS,OU=Marketing,DC=RAM,DC=COM"
.
我想将字符拆分为第一个逗号(,)之后,这意味着我只需要
OU=Marketing,DC=RAM,DC=COM.
我已经尝试了strtok
功能,但它只拆分了CN = USERS。
我怎样才能做到这一点?
尝试下面的代码,您应该能够轻松获取每个项目(用","分隔):斯特托克版本:
char domain[] = "CN=USERS,OU=Marketing,DC=RAM,DC=COM";
char *token = std::strtok(domain, ",");
while (token != NULL) {
std::cout << token << 'n';
token = std::strtok(NULL, ",");
}
标准::字符串流版本:
std::stringstream ss("CN=USERS,OU=Marketing,DC=RAM,DC=COM");
std::string item;
while(std::getline(ss, item, ','))
{
cout << item << endl;
}
看看 std::getline()http://en.cppreference.com/w/cpp/string/basic_string/getline
使用strchr
使它变得非常简单:
char domain[] = "CN=USERS,OU=Marketing,DC=RAM,DC=COM";
char *p = strchr(domain, ',');
if (p == NULL)
{
// error, no comma in the string
}
++p; // point to the character after the comma
相关文章:
- 如何根据字符拆分字符串
- 使用连续分隔符和空最后一个字符进行拆分
- 拆分字符数组并存储为向量
- 通过拆分字符数组来创建字符串
- 拆分字符串输入并查找字符是否有效
- 通过正则表达式拆分字符串会切断结果的第一个字母
- C++ 如何将字符串拆分为单个字符
- 如何将字符串拆分为一组 3 个字符,它们之间有空格
- C++ 中的解析器/拆分常量字符*
- 将字符拆分为字符数组
- 在独立模式 c++ 中分隔符处拆分字符*
- 如何使用 c++ win32 API 拆分字符
- boost::algorithm - 拆分字符串会返回一个额外的标记
- CUDA 拆分字符数组
- 在空格之间拆分字符数组
- 拆分字符数组
- 如何在不使用任何基本函数的情况下拆分字符数组
- 如何在c ++中用多个分隔符拆分字符指针并返回字符指针数组?
- 如何创建一个字符串数组来拆分字符,其中单词由" "分隔?C++
- c++拆分字符串会产生奇怪的输出