76 lines
2 KiB
Text
76 lines
2 KiB
Text
' version 20-06-2015
|
|
' compile with: fbc -s console "filename".bas
|
|
|
|
#Ifndef TRUE ' define true and false for older freebasic versions
|
|
#Define FALSE 0
|
|
#Define TRUE Not FALSE
|
|
#EndIf
|
|
|
|
Function reverse(norm As String) As Integer
|
|
|
|
Dim As String rev
|
|
Dim As Integer i, l = Len(norm) -1
|
|
|
|
rev = norm
|
|
For i = 0 To l
|
|
rev[l-i] = norm[i]
|
|
Next
|
|
|
|
If norm = rev Then
|
|
Return TRUE
|
|
Else
|
|
Return FALSE
|
|
End If
|
|
|
|
End Function
|
|
|
|
Function cleanup(in As String, action As String = "") As String
|
|
' action = "" do nothing, [l|L] = convert to lowercase,
|
|
' [s|S] = strip spaces, [p|P] = strip punctuation.
|
|
If action = "" Then Return in
|
|
|
|
Dim As Integer i, p_, s_
|
|
Dim As String ch
|
|
|
|
action = LCase(action)
|
|
For i = 1 To Len(action)
|
|
ch = Mid(action, i, 1)
|
|
If ch = "l" Then in = LCase(in)
|
|
If ch = "p" Then
|
|
p_ = 1
|
|
ElseIf ch = "s" Then
|
|
s_ = 1
|
|
End If
|
|
Next
|
|
|
|
If p_ = 0 And s_ = 0 Then Return in
|
|
|
|
Dim As String unwanted, clean
|
|
|
|
If s_ = 1 Then unwanted = " "
|
|
If p_ = 1 Then unwanted = unwanted + "`~!@#$%^&*()-=_+[]{}\|;:',.<>/?"
|
|
|
|
For i = 1 To Len(in)
|
|
ch = Mid(in, i, 1)
|
|
If InStr(unwanted, ch) = 0 Then clean = clean + ch
|
|
Next
|
|
|
|
Return clean
|
|
|
|
End Function
|
|
|
|
' ------=< MAIN >=------
|
|
|
|
Dim As String test = "In girum imus nocte et consumimur igni"
|
|
'IIf ( cond, true, false ), true and false must be of the same type (num, string, UDT)
|
|
Print
|
|
Print " reverse(test) = "; IIf(reverse(test) = FALSE, "FALSE", "TRUE")
|
|
Print " reverse(cleanup(test,""l"")) = "; IIf(reverse(cleanup(test,"l")) = FALSE, "FALSE", "TRUE")
|
|
Print " reverse(cleanup(test,""ls"")) = "; IIf(reverse(cleanup(test,"ls")) = FALSE, "FALSE", "TRUE")
|
|
Print "reverse(cleanup(test,""PLS"")) = "; IIf(reverse(cleanup(test,"PLS")) = FALSE, "FALSE", "TRUE")
|
|
|
|
' empty keyboard buffer
|
|
While InKey <> "" : Wend
|
|
Print : Print : Print "Hit any key to end program"
|
|
Sleep
|
|
End
|