[Solved] searching sub string in string and check another string before that [closed]


Here ya go, use std::string::find:

// Notice the double quotes
std::string::size_type position = my_string.find("34");
bool found = 
 ((position != std::string::npos) && (position > 0) && (my_string[position - 1] == '6'));

The find method returns the position of substring, or std::string::npos if it is not found.

The position must be greater than 0, because of the “before” requirement.

If both conditions are satisified, the character slot before the “34” is checked for ‘6’, and assigned to a boolean variable.

3

solved searching sub string in string and check another string before that [closed]