String comparison: Difference between revisions

Added solution for Action!
m (→‎{{header|Phix}}: added personal tag, made runnable, added output)
(Added solution for Action!)
Line 243:
.include "../includeARM64.inc"
</lang>
 
=={{header|Action!}}==
<lang Action!>PROC TestEqual(CHAR ARRAY s1,s2)
INT res
 
PrintF("""%S"" and ""%S"" are equal: ",s1,s2)
IF SCompare(s1,s2)=0 THEN
PrintE("True")
ELSE
PrintE("False")
FI
RETURN
 
PROC TestInequal(CHAR ARRAY s1,s2)
INT res
 
PrintF("""%S"" and ""%S"" are inequal: ",s1,s2)
IF SCompare(s1,s2)#0 THEN
PrintE("True")
ELSE
PrintE("False")
FI
RETURN
 
PROC TestBefore(CHAR ARRAY s1,s2)
INT res
 
PrintF("""%S"" is before ""%S"": ",s1,s2)
IF SCompare(s1,s2)<0 THEN
PrintE("True")
ELSE
PrintE("False")
FI
RETURN
 
PROC TestAfter(CHAR ARRAY s1,s2)
INT res
 
PrintF("""%S"" is after ""%S"": ",s1,s2)
IF SCompare(s1,s2)>0 THEN
PrintE("True")
ELSE
PrintE("False")
FI
RETURN
 
PROC TestNumEqual(CHAR ARRAY s1,s2)
INT v1,v2
 
PrintF("""%S"" and ""%S"" are equal: ",s1,s2)
v1=ValI(s1) v2=ValI(s2)
IF v1=v2 THEN
PrintE("True")
ELSE
PrintE("False")
FI
RETURN
 
PROC TestNumInequal(CHAR ARRAY s1,s2)
INT v1,v2
 
PrintF("""%S"" and ""%S"" are inequal: ",s1,s2)
v1=ValI(s1) v2=ValI(s2)
IF v1#v2 THEN
PrintE("True")
ELSE
PrintE("False")
FI
RETURN
 
PROC TestNumBefore(CHAR ARRAY s1,s2)
INT v1,v2
 
PrintF("""%S"" is before ""%S"": ",s1,s2)
v1=ValI(s1) v2=ValI(s2)
IF v1<v2 THEN
PrintE("True")
ELSE
PrintE("False")
FI
RETURN
 
PROC TestNumAfter(CHAR ARRAY s1,s2)
INT v1,v2
 
PrintF("""%S"" is after ""%S"": ",s1,s2)
v1=ValI(s1) v2=ValI(s2)
IF v1>v2 THEN
PrintE("True")
ELSE
PrintE("False")
FI
RETURN
 
PROC Main()
PrintE("Lexical comparison:")
TestEqual("abcd","Abcd")
TestInequal("abcd","Abcd")
TestBefore("abcd","Abcd")
TestAfter("abcd","Abcd")
PutE()
 
PrintE("Numerical comparison:")
TestNumEqual("1234","99876")
TestNumInequal("1234","99876")
TestNumBefore("1234","99876")
TestNumAfter("1234","99876")
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/String_comparison.png Screenshot from Atari 8-bit computer]
<pre>
Lexical comparison:
"abcd" and "Abcd" are equal: False
"abcd" and "Abcd" are inequal: True
"abcd" is before "Abcd": False
"abcd" is after "Abcd": True
 
Numerical comparison:
"1234" and "99876" are equal: False
"1234" and "99876" are inequal: True
"1234" is before "99876": False
"1234" is after "99876": True
</pre>
 
=={{header|Ada}}==
Anonymous user