Removing everything after character (and also character)

前端 未结 3 1926
星月不相逢
星月不相逢 2021-01-02 01:16

I have a string like this:

std::string string1 = \"xjdfhfakdjs%54k34k.-jk34\";

I need to get only \"\"xjdfhfakdjs\", but the string is dyna

3条回答
  •  礼貌的吻别
    2021-01-02 02:16

    std::string the_prefix_you_want = string1.substr(0, string1.find("%"));
    

    See: http://www.cplusplus.com/reference/string/string/find/ and http://www.cplusplus.com/reference/string/string/substr/ for more details

提交回复
热议问题