使用C 中的特殊格式拆分字符串
Split a string a string using special formatting in c++
我正在尝试分开这样的字符串:
" aaaaaaaa" 1 " bbbbbbbbb"
随附的引号,以获取AAAAAAAAA BBBBBBBBB。
我找到了不同的方法来划分字符串,但引号和斜线的存在引起了许多问题。
例如,如果我使用string.find,我不能使用string.find(" 1 ");
有人知道如何帮助我吗?谢谢
#include <iostream>
#include <string>
#include <regex>
int main()
{
// build a test string and display it
auto str = std::string(R"text("aaaaaaaa"1"bbbbbbbbb")text");
std::cout << "input : " << str << std::endl;
// build the regex to extract two quoted strings separated by "1"
std::regex re(R"regex("(.*?)"\1\"(.*?)")regex");
std::smatch match;
// perform the match
if (std::regex_match(str, match, re))
{
// print captured groups on success
std::cout << "matched : " << match[1] << " and " << match[2] << std::endl;
}
}
预期结果:
input : "aaaaaaaa"1"bbbbbbbbb"
matched : aaaaaaaa and bbbbbbbbb
相关文章:
- 如何在openssl-ecc中获取十六进制格式的私钥
- 将"打开的CV图像"中的"颜色"转换为整数格式
- TDateTime格式在C++Builder中不会更改
- C++将向量的向量拆分为向量的N个子向量
- 如何防止clang格式在流运算符调用之间添加换行符<<
- 检查不带转换的扫描格式
- 当我尝试使用 sstream 和分面将 Boost Time_duration转换为字符串时,我没有得到所需的格式
- 是否可以从格式字符串中检索"width"
- clang格式:宏的缩进
- clang格式:禁用排序包含
- 在用于格式4的arm模拟器中实现功能时的一个问题
- 将RGB图像保存为PPM格式
- 询问在设计我的手臂模拟器功能表示格式1
- 拆分学生名单,格式如:0001 William Bill Junior 8.5
- 将特定格式的字符串拆分为浮点数和字符串
- 使用C 中的特殊格式拆分字符串
- 以 C/C++ 格式拆分输出以进行重定向
- 将大型数据文件拆分为多个小文件(文本格式)
- 使用C++拆分"[General Setting]"格式的部分字符串
- 正在拆分从int向量创建的特定格式的字符串