Compare length of two strings: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 696:
</pre>
 
=={{header|FutureBasic}}==
<lang futurebasic>local fn MyArraySortFunction( obj1 as CFTypeRef, obj2 as CFTypeRef, context as ptr ) as NSComparisonResult
NSComparisonResult result = NSOrderedDescending
if len(obj1) >= len(obj2) then result = NSOrderedAscending
end fn = result
 
void local fn DoIt
CFStringRef string1 = @"abcd", string2 = @"abcdef", s
 
if len(string1) >= len(string2)
print string1,len(string1)
print string2,len(string2)
else
print string2,len(string2)
print string1,len(string1)
end if
 
print
text ,,,,, 85
 
CFArrayRef strings = @[@"abcd",@"123456789",@"abcdef",@"1234567"]
strings = fn ArraySortedArrayUsingFunction( strings, @fn MyArraySortFunction, NULL )
for s in strings
print s,len(s)
next
end fn
 
window 1
 
fn DoIt
 
HandleEvents</lang>
 
Output:
<pre>abcdef 6
abcd 4
 
123456789 9
1234567 7
abcdef 6
abcd 4</pre>
=={{header|Harbour}}==
We can, easily, realize this task with Harbour, utilizing its strong array-handling set of functions.
416

edits