C++;正则表达式来提取子字符串 我如何在C++字符中提取一个子字符串。例如,如果我有一个字符串 ASDG::DS"G*0asd}}345sdgfsdfg
我该如何提取该部分C++;正则表达式来提取子字符串 我如何在C++字符中提取一个子字符串。例如,如果我有一个字符串 ASDG::DS"G*0asd}}345sdgfsdfg,c++,regex,string,substring,C++,Regex,String,Substring,我该如何提取该部分 ASDG::DS"G 你当然不需要正则表达式。只需使用和: #包括 int main() { //原始字符串需要C++-11 std::string s1=R“(ASDG::DS“G*0asd}}345sdgfsdfg)”; std::string s2=s1.substr(0,s1.find('*'); } 您当然不需要正则表达式。只需使用和: #包括 int main() { //原始字符串需要C++-11 std::string s1=R“(ASDG::DS“G*0a
ASDG::DS"G
你当然不需要正则表达式。只需使用和:
#包括
int main()
{
//原始字符串需要C++-11
std::string s1=R“(ASDG::DS“G*0asd}}345sdgfsdfg)”;
std::string s2=s1.substr(0,s1.find('*');
}
您当然不需要正则表达式。只需使用和:
#包括
int main()
{
//原始字符串需要C++-11
std::string s1=R“(ASDG::DS“G*0asd}}345sdgfsdfg)”;
std::string s2=s1.substr(0,s1.find('*');
}
我认为您的文本没有多个*
,因为查找返回第一个*
#include <iostream>
#include <string>
using namespace std;
#define SELECT_END_CHAR "*"
int main(){
string text = "ASDG::DS\"G*0asd}}345sdgfsdfg";
unsigned end_index = text.find(SELECT_END_CHAR);
string result = text.substr (0,end_index);
cout << result << endl;
system("pause");
return 0;
}
#包括
#包括
使用名称空间std;
#定义选择结束字符“*”
int main(){
string text=“ASDG::DS\”G*0asd}}345sdgfsdfg”;
unsigned end\u index=text.find(选择\u end\u CHAR);
字符串结果=text.substr(0,结束索引);
cout我认为您的文本没有多个*
,因为查找
返回第一个*
#include <iostream>
#include <string>
using namespace std;
#define SELECT_END_CHAR "*"
int main(){
string text = "ASDG::DS\"G*0asd}}345sdgfsdfg";
unsigned end_index = text.find(SELECT_END_CHAR);
string result = text.substr (0,end_index);
cout << result << endl;
system("pause");
return 0;
}
#包括
#包括
使用名称空间std;
#定义选择结束字符“*”
int main(){
string text=“ASDG::DS\”G*0asd}}345sdgfsdfg”;
unsigned end\u index=text.find(选择\u end\u CHAR);
字符串结果=text.substr(0,结束索引);
库特