c++ - Is string::compare reliable to determine alphabetical order? -


Simply put, if the input is always in the same case (here, the short case), and if the character is always ASCII , Can use string: can compare two strings to determine the alphabet sequence?

Thus, if the result is 0 with stringA.compare (stringB) , then that same, if it is negative, string A stringb comes alphabetically, and if It's positive, what comes after string A? According to the docs at cplusplus.com,

The Member Function 0 returns if the comparison material is made.

If all the characters compare the same, then a negative value if the first character that does not match is less in the object than the comparison string, and a positive value in the opposite case.

Therefore it will sort the strings in ASCII sequence, which will be alphabetical for English strings (without any diacritical digits or otherwise extended characters)


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -