String comparison: Difference between revisions

Added BBC BASIC
m (added whitespace before the TOC (table of contents), added a ;Related tasks; (bold) header.)
(Added BBC BASIC)
Line 412:
For case sensitive comparisons {{works with|Applesoft BASIC}}
Applesoft BASIC does not have a built in UPPER$ function.
 
=={{header|BBC BASIC}}==
<lang bbcbasic>REM >strcomp
shav$ = "Shaw, George Bernard"
shakes$ = "Shakespeare, William"
:
REM test equality
IF shav$ = shakes$ THEN PRINT "The two strings are equal" ELSE PRINT "The two strings are not equal"
:
REM test inequality
IF shav$ <> shakes$ THEN PRINT "The two strings are unequal" ELSE PRINT "The two strings are not unequal"
:
REM test lexical ordering
IF shav$ > shakes$ THEN PRINT shav$; " is lexically higher than "; shakes$ ELSE PRINT shav$; " is not lexically higher than "; shakes$
IF shav$ < shakes$ THEN PRINT shav$; " is lexically lower than "; shakes$ ELSE PRINT shav$; " is not lexically lower than "; shakes$
REM the >= and <= operators can also be used, & behave as expected
:
REM string comparison is case-sensitive by default, and BBC BASIC
REM does not provide built-in functions to convert to all upper
REM or all lower case; but it is easy enough to define one
:
IF FN_upper(shav$) = FN_upper(shakes$) THEN PRINT "The two strings are equal (disregarding case)" ELSE PRINT "The two strings are not equal (even disregarding case)"
END
:
DEF FN_upper(s$)
LOCAL i%, ns$
ns$ = ""
FOR i% = 1 TO LEN s$
IF ASC(MID$(s$, i%, 1)) >= ASC "a" AND ASC(MID$(s$, i%, 1)) <= ASC "z" THEN ns$ += CHR$(ASC(MID$(s$, i%, 1)) - &20) ELSE ns$ += MID$(s$, i%, 1)
NEXT
= ns$</lang>
{{out}}
<pre>The two strings are not equal
The two strings are unequal
Shaw, George Bernard is lexically higher than Shakespeare, William
Shaw, George Bernard is not lexically lower than Shakespeare, William
The two strings are not equal (even disregarding case)</pre>
 
=={{header|Bracmat}}==
519

edits