2013-04-11 35 views

回答

3

你肯定不会需要一个正则表达式。只需使用std::string::find('*')std::string::substr

#include <string> 

int main() 
{ 
    // raw strings require C++-11 
    std::string s1 = R"(ASDG::DS"G*0asd}}345sdgfsdfg)"; 
    std::string s2 = s1.substr(0, s1.find('*')); 
} 
0

我觉得你的文本没有多*因为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; 
}