Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
37
Task/String-comparison/PureBasic/string-comparison.basic
Normal file
37
Task/String-comparison/PureBasic/string-comparison.basic
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue