38 lines
1.8 KiB
Plaintext
38 lines
1.8 KiB
Plaintext
Macro StrTest(Check,tof)
|
|
Print("Test "+Check+#TAB$)
|
|
If tof=1 : PrintN("true") : Else : PrintN("false") : EndIf
|
|
EndMacro
|
|
|
|
Procedure.b StrBool_eq(a$,b$) : ProcedureReturn Bool(a$=b$) : EndProcedure
|
|
Procedure.b StrBool_n_eq(a$,b$) : ProcedureReturn Bool(a$<>b$) : EndProcedure
|
|
Procedure.b StrBool_a(a$,b$) : ProcedureReturn Bool(a$>b$) : EndProcedure
|
|
Procedure.b StrBool_b(a$,b$) : ProcedureReturn Bool(a$<b$) : EndProcedure
|
|
Procedure.b NumBool_eq(a$,b$) : ProcedureReturn Bool(Val(a$)=Val(b$)) : EndProcedure
|
|
Procedure.b NumBool_n_eq(a$,b$) : ProcedureReturn Bool(Val(a$)<>Val(b$)) : EndProcedure
|
|
Procedure.b NumBool_a(a$,b$) : ProcedureReturn Bool(Val(a$)>Val(b$)) : EndProcedure
|
|
Procedure.b NumBool_b(a$,b$) : ProcedureReturn Bool(Val(a$)<Val(b$)) : EndProcedure
|
|
|
|
Procedure Compare(a$,b$,cs.b=1,num.b=0)
|
|
If Not cs : a$=UCase(a$) : b$=UCase(b$) : EndIf
|
|
PrintN("a = "+a$) : PrintN("b = "+b$)
|
|
If Not num : StrTest(" a=b ",StrBool_eq(a$,b$)) : Else : StrTest(" a=b ",NumBool_eq(a$,b$)) : EndIf
|
|
If Not num : StrTest(" a<>b ",StrBool_n_eq(a$,b$)) : Else : StrTest(" a<>b ",NumBool_n_eq(a$,b$)) : EndIf
|
|
If Not num : StrTest(" a>b ",StrBool_a(a$,b$)) : Else : StrTest(" a>b ",NumBool_a(a$,b$)) : EndIf
|
|
If Not num : StrTest(" a<b ",StrBool_b(a$,b$)) : Else : StrTest(" a<b ",NumBool_b(a$,b$)) : EndIf
|
|
EndProcedure
|
|
|
|
If OpenConsole()
|
|
PrintN("String comparison - ")
|
|
a$="Abcd" : b$="abcd"
|
|
PrintN(#CRLF$+"- case sensitive:")
|
|
Compare(a$,b$)
|
|
PrintN(#CRLF$+"- case insensitive:")
|
|
Compare(a$,b$,0)
|
|
a$="1241" : b$="222"
|
|
PrintN(#CRLF$+"- num-string; lexically compared:")
|
|
Compare(a$,b$)
|
|
PrintN(#CRLF$+"- num-string; numerically compared:")
|
|
Compare(a$,b$,1,1)
|
|
Input()
|
|
EndIf
|