Mbee Posted April 29, 2016 Share Posted April 29, 2016 I'm sorting an array of strings, alphabetically ascending. It's essential for my algorithm that the shortest of the variant strings always appear first. That is, if the original array contains the following: potential potentiometer potent Potentials ... the output array must always have the following order: potent potential Potentials potentiometer It seems logical that this would always be the case, but I need to be certain. Will this always be the case? Thanks! Link to comment Share on other sites More sharing options...
czardas Posted April 29, 2016 Share Posted April 29, 2016 The short answer is yes for strings. For numbers no because the size is what counts. Mbee 1 operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Mbee Posted April 29, 2016 Author Share Posted April 29, 2016 Thanks, czardas! I appreciate the confirmation. czardas 1 Link to comment Share on other sites More sharing options...
iamtheky Posted April 29, 2016 Share Posted April 29, 2016 for strings its not what counts either, unless you already know which sets go together and they arent already sorted alphabetically... hug huge hugs hugest huggers ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
czardas Posted April 29, 2016 Share Posted April 29, 2016 (edited) Unless I misunderstood, the point is that the strings will all begin with the same sequence. Then longer strings are always greater than smaller strings within these sets. You can get a greater understanding by trying StringCompare(), which is the comparison function used for sorting strings. hug huge hugest huggers hugs Huggers has a new 4th character 'g' which is greater than 'e', so alphabetical sequences always take precedence (naturally!). Then anything that comes after the duplicated sequence is considered to be greater: just like in a dictionary. If you are using this to replace strings; then loop through, or sort, the array in reverse. This will avoid replacing half a word by accident. It's also quite easy to create a string length sort function. Edited April 29, 2016 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
iamtheky Posted April 29, 2016 Share Posted April 29, 2016 Yeah, after thinking more the groups would have to be preset or you'd be boned. I was more thinking that huge and hugest should be in their own list according to OP rules, but there would be no feasible way to discern that sort of thing. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
czardas Posted April 29, 2016 Share Posted April 29, 2016 (edited) It's how I interpreted the question. In the list, the word potentiometer breaks the pattern at the 8th character (...ometer). With the other three; once sorted, shorter words are completely contained within the longer versions (the start of the pattern repeats in its entirety - each time growing in size). The question may seem basic, but it's not necessarily obvious. I did some similar tests myself recently because I wasn't sure if the strings '1.' and '1.0' would be considered equal: as strings they are not. The character '0' is greater than no character at all! I guess that's good thinking. Edited April 29, 2016 by czardas Mbee 1 operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now