go to the freebasic part
I know we can handle string with left/mid/right functions, but
1. this makes the code so long
2. it is hard (ok, actually I mean it will do hard to keyboard ;) ) to realize
Code: Select all
s[1:10:2]
s[10:1:-2]
s[:-1]
s[::-1]
So, I have 2 questions
1. Is there any existing function/oop to handle this
2. if not, I am trying to write an OOP solution. But how can I judge which argument(s) are not passed in to "Function T_PythonString.index" during calling? so that I can do
Code: Select all
' I think maybe only function overload can do this
s.index(1)
' I think maybe only function overload can do this
s.index(1, 2)
' I don't know how to handle this. I don't think it is a best solution to give idxStart a very big value as default value, then judge 'if idxStart=theBiggestValue Then idxStart=default end if'
s.index(, -1)
s.index(, , -2)
the following is what I have now
Code: Select all
' please fix this code
type T_PythonString
content as string
idxStart as long
idxEnd as long
step_ as long
declare constructor ( _
byval content as String = "" _
)
Declare Operator Let(ByRef s As String)
declare Function index( _
byval idxStart as long , _
byval idxEnd as long , _
byval step_ as long = 1_
) As string
end type
constructor T_PythonString ( _
ByVal s as String ="" _
)
this.content = s
end constructor
Operator T_PythonString.Let(ByRef s As String)
content = s
End Operator
Function T_PythonString.index( _
byval idxStart as long , _
byval idxEnd as long , _
byval step_ as long = 1_
) As string:
? idxStart
return this.content
End Function
Dim as T_PythonString s = "Hello"
print s.content
? s.index(,,)
Thanks