Filter a string

how can i filter a string ? let say i have this string 255-100-10-test.png and i only want the 255 or 100 of the string .

Hi aliva,
take a look to ofSplitString, it should resolve your problem.

1 Like

Or you can use substring method:

std::string inputStr;
std::string partStr;
partStd = inputStr.substr(0, 3);
1 Like

you should take a look at regular expressions. The split string way should work but regular expressions are much more flexible

1 Like

cool! and how can i sort the string descending , do i have to convert the string to a integer to make it happen?

Hi aliva,
it could be done with the std namespace.
It contains a sort function that order ascending and it can be used with a string.
After sorting the string, use reverse function to achieve the result.

Something like that should work:

string str = "adbce";
std::sort(str.begin(), str.end()); //sort it ("abcde")
std::reverse(str.begin(), str.end()); //reverse it ("edcba")