String comparison: Difference between revisions

m
(Add WDTE example.)
Line 1,134:
IN: scratchpad "a1" "a03" human<=> . ! comparing numeric strings like a human
+lt+</lang>
 
 
=={{header|Falcon}}==
'''VBA/Python programmer's approach. I'm just a junior Falconeer but this code seems to go the falcon way''
<lang falcon>
/* created by Aykayayciti Earl Lamont Montgomery
April 9th, 2018 */
 
e = "early"
l = "toast"
g = "cheese"
b = "cheese"
e2 = "early"
num1 = 123
num2 = 456
 
> e == e2 ? @ "$e equals $e2" : @ "$e does not equal $e2"
> e != e2 ? @ "$e does not equal $e2": @ "$e equals $e2"
// produces -1 for less than
> b.cmpi(l) == 1 ? @ "$b is grater than $l" : @ "$l is grater than $b"
// produces 1 for greater than
> l.cmpi(b) == 1 ? @ "$l is grater than $b" : @ "$b is grater than $l"
// produces 0 for equal (but could be greater than or equal)
> b.cmpi(g) == 1 or b.cmpi(g) == 0 ? @ "$b is grater than or equal to $g" : @ "$b is not >= $g"
// produces 0 for equal (but could be less than or equal)
>b.cmpi(g) == -1 or b.cmpi(g) == 0 ? @ "$b is less than or equal to $g" : @ "$b is not <= $g"
 
function NumCompare(num1, num2)
if num1 < num2
ans = " < "
elif num1 > num2
ans = " > "
else
ans = " = "
end
return ans
end
 
result = NumCompare(num1, num2)
> @ "$num1 $result $num2"
</lang>
{{out}}
<pre>
early equals early
early equals early
toast is grater than cheese
toast is grater than cheese
cheese is grater than or equal to cheese
cheese is less than or equal to cheese
123 < 456
[Finished in 0.2s]
</pre>
 
=={{header|Forth}}==