Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
12
Task/Reverse-a-string/VBA/reverse-a-string-1.vba
Normal file
12
Task/Reverse-a-string/VBA/reverse-a-string-1.vba
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
Public Function Reverse(aString as String) as String
|
||||
' returns the reversed string
|
||||
dim L as integer 'length of string
|
||||
dim newString as string
|
||||
|
||||
newString = ""
|
||||
L = len(aString)
|
||||
for i = L to 1 step -1
|
||||
newString = newString & mid$(aString, i, 1)
|
||||
next
|
||||
Reverse = newString
|
||||
End Function
|
||||
14
Task/Reverse-a-string/VBA/reverse-a-string-2.vba
Normal file
14
Task/Reverse-a-string/VBA/reverse-a-string-2.vba
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
Public Function RReverse(aString As String) As String
|
||||
'returns the reversed string
|
||||
'do it recursively: cut the string in two, reverse these fragments and put them back together in reverse order
|
||||
Dim L As Integer 'length of string
|
||||
Dim M As Integer 'cut point
|
||||
|
||||
L = Len(aString)
|
||||
If L <= 1 Then 'no need to reverse
|
||||
RReverse = aString
|
||||
Else
|
||||
M = Int(L / 2)
|
||||
RReverse = RReverse(Right$(aString, L - M)) & RReverse(Left$(aString, M))
|
||||
End If
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue