How would you compare strings when the characters (
and )
should come after the alphanumeric characters. Do I have to write a function or is there any library function avai开发者_Go百科lable?
Thank you for your answers!
You can use std::lexicographical_compare
with a custom predicate. That predicate should take 2 chars, and return false if the first should come before the second.
There's no built in way to do this. You'll have to write your own comparison function/functor. I believe you can however implement this with character traits so that operator<
still works, but you won't be using std::string
anymore.
- Copy both strings that are to be compared to temporary strings
- In both strings, replace
(
and)
with characters that come after alphanumeric characters in the particular encoding you're using - Compare the manipulated results with standard library comparing function
- Use the result of function and dispose of the manipulated strings
For instance, (
and )
come before alphanumeric characters in ASCII, but {
and }
come after!
some environments have provision for custom collation sequences, but generally speaking you have to write your own.
精彩评论