Jump to content

String comparison: Difference between revisions

FutureBasic solution added
(FutureBasic solution added)
Line 2,161:
Dog is equal to dog if case is ignored
Dog is not equal to Pig
</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
void local fn StringComparison
CFStringRef s1, s2
NSComparisonResult result
window 1, @"String Comparison"
print @"• equal - case sensitive •"
s1 = @"alpha" : s2 = @"alpha"
if ( fn StringIsEqual( s1, s2 ) )
printf @"\"%@\" is equal to \"%@\"",s1,s2
end if
result = fn StringCompare( s1, s2 )
if ( result == NSOrderedSame )
printf @"\"%@\" is equal to \"%@\"",s1,s2
end if
select ( s1 )
case s2
printf @"\"%@\" is equal to \"%@\"",s1,s2
case else
printf @"\"%@\" is not equal to \"%@\"",s1,s2
end select
print @"\n• not equal - case sensitive •"
s2 = @"bravo"
if ( fn StringIsEqual( s1, s2 ) == NO )
printf @"\"%@\" is not equal to \"%@\"",s1,s2
end if
result = fn StringCompare( s1, s2 )
if ( result != NSOrderedSame )
printf @"\"%@\" is not equal to \"%@\"",s1,s2
end if
select ( s1 )
case s2
printf @"\"%@\" is equal to \"%@\"",s1,s2
case else
printf @"\"%@\" is not equal to \"%@\"",s1,s2
end select
print @"\n• ordered before - case sensitive •"
result = fn StringCompare( s1, s2 )
if ( result == NSOrderedAscending )
printf @"\"%@\" is ordered before \"%@\"",s1,s2
end if
print @"\n• ordered after - case sensitive •"
result = fn StringCompare( s2, s1 )
if ( result == NSOrderedDescending )
printf @"\"%@\" is ordered after \"%@\"",s2,s1
end if
print @"\n• equal - case insensitive •"
s2 = @"AlPhA"
result = fn StringCaseInsensitiveCompare( s1, s2 )
if ( result == NSOrderedSame )
printf @"\"%@\" is equal to \"%@\"",s1,s2
end if
result = fn StringCompareWithOptions( s1, s2, NSCaseInsensitiveSearch )
if ( result == NSOrderedSame )
printf @"\"%@\" is equal to \"%@\"",s1,s2
end if
if ( fn StringIsEqual( lcase(s1), lcase(s2) ) )
printf @"\"%@\" is equal to \"%@\"",s1,s2
end if
end fn
 
fn StringComparison
 
HandleEvents
</syntaxhighlight>
 
{{out}}
<pre>
• equal - case sensitive •
"alpha" is equal to "alpha"
"alpha" is equal to "alpha"
"alpha" is equal to "alpha"
 
• not equal - case sensitive •
"alpha" is not equal to "bravo"
"alpha" is not equal to "bravo"
"alpha" is not equal to "bravo"
 
• ordered before - case sensitive •
"alpha" is ordered before "bravo"
 
• ordered after - case sensitive •
"bravo" is ordered after "alpha"
 
• equal - case insensitive •
"alpha" is equal to "AlPhA"
"alpha" is equal to "AlPhA"
"alpha" is equal to "AlPhA"
</pre>
 
416

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.