String comparison: Difference between revisions

m
BBC BASIC moved to the BASIC section.
m (→‎Unicode normalization by default: A little less negative about following the Unicode spec)
m (BBC BASIC moved to the BASIC section.)
Line 1,108:
{{out}}
<pre>Igual que la entrada de FreeBASIC.</pre>
 
==={{header|BBC BASIC}}===
<syntaxhighlight 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$</syntaxhighlight>
{{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|QBasic}}===
Line 1,277 ⟶ 1,314:
0 OK, 0:673
</pre>
 
=={{header|BBC BASIC}}==
<syntaxhighlight 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$</syntaxhighlight>
{{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}}==
512

edits