Jump to content

String comparison: Difference between revisions

Line 94:
20 LET B$="belt"
30 IF UPPER$(A$)=UPPER$(B$) THEN PRINT "Disregarding lettercase, the strings are the same."</lang>
 
=={{header|Bracmat}}==
String comparison in Bracmat is performed by pattern matching using an atomic pattern.
The atomic pattern can be prefixed with <code>&lt;</code>, <code>&gt;</code>, <code>~</code> or <code>%</code> or combinations thereof.
<lang bracmat>( {Comparing two strings for exact equality}
& ( ( @(abc:abc)
& @(123:%123)
{Previous pairs of strings are exactly equal}
)
& ( @(abc:Abc)
| @(123:%246/2)
| @(abc:ab)
| @(123:%12)
| {Previous pairs of strings are not exactly equal}
)
)
{Comparing two strings for inequality (i.e., the inverse of exact equality)}
& ( ( @(abc:~<>abc)
& @(abc:~<>Abc)
{Previous pairs of strings are more or less equal}
)
& ( @(abc:~<>ab)
| {Previous pairs of strings are not more or less equal}
)
)
{Comparing two strings to see if one is lexically ordered before than the other}
& ( ( @(Abc:<abc)
& @(Abc:<a)
& @(123:<%246/2)
& @(123:<%2)
& @(12:<%123)
& @(ab:<abc)
{Previous pairs of strings are lexically ordered one before the other}
)
& ( @(abc:<abc)
| @(abc:<Abc)
| @(246/2:<%123)
| @(abc:<ab)
| @(123:<%12)
| @(123:<%123)
| {Previous pairs of strings are not lexically ordered one before the other}
)
)
{Comparing two strings to see if one is lexically ordered after than the other}
& ( ( @(abc:>Abc)
& @(a:>Abc)
& @(246/2:>%123)
& @(2:>%123)
& @(123:>%12)
& @(abc:>ab)
{Previous pairs of strings are lexically ordered one after the other}
)
& ( @(abc:>abc)
| @(Abc:>abc)
| @(123:>%246/2)
| @(ab:>abc)
| @(12:>%123)
| @(123:>%123)
| {Previous pairs of strings are not lexically ordered one after the other}
)
)
{How to achieve both case sensitive comparisons and case insensitive comparisons within
the language}
& ( ( @(abc:~<>abc)
& @(abc:~<>Abc)
& @(БЪЛГАРСКИ:~<>български)
{Previous pairs of strings are more or less equal}
)
& ( @(abc:~<>ab)
| {Previous pairs of strings are not more or less equal}
)
)
{How the language handles comparison of numeric strings if these are not treated lexically}
& ( ( @(246/2:123)
& @(2:<123)
& @(123:>12)
& @(123:246/2)
& @(12:<123)
{Previous numeric string comparisons succeed}
)
& ( @(123:<246/2)
| @(12:>123)
| @(123:>123)
| @(123:~123)
| {Previous numeric string comparisons fail}
)
)
{Demonstrate any other kinds of string comparisons that the language provides, particularly
as it relates to your type system. For example, you might demonstrate the difference between
generic/polymorphic comparison and coercive/allomorphic comparison if your language supports
such a distinction.}
& ( ( @(246/2:>12--3)
& @(2:>123kg)
& @(123:<12d)
& @(123:~24/6/2)
& @(12a:>123)
{Previous coercive string comparisons succeed}
)
& ( @(2013-05-01:20130501)
| @(246/2a:123a)
| @(1239:<123-)
| {Previous coercive string comparisons fail}
)
)
& done
);</lang>
 
=={{header|Burlesque}}==
483

edits

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