I would recommend to just get rid of the first "non-numerical" characters and use atoi function. Something like:
char *get_first_num(char *s) { while( (*s < '0') || (*s >'9') ) ++s; return s; } int main() { char *a = "b005b"; cout << atoi(get_first_num(a)) << endl; return 0; } So then you can compare your numbers as: atoi(get_first_num(a)) < atoi(get_first_num(b)) On Tuesday, 17 April 2012 20:18:13 UTC-7, Abhishek wrote: > > Hi, > > I need to compare string into following way. Can anyone provide me some > insight or algorithm in c++. > > For example: > > "a5" < "a11" - because 5 is less than 11 > "6xxx < 007asdf" - because 6 < 7 > "00042Q < 42s" - because Q < s alphabetically > "6 8" < "006 9" - because 8 < 9 > > > > Thx in advance > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/LMz9srnKdE4J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.