chamsi09

Untitled

Nov 15th, 2024
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.63 KB | None | 0 0
  1. Module Module1
  2.     Sub Main()
  3.         Dim input As String = "hello"
  4.         Dim reversed As String = ReverseString(input)
  5.         Console.WriteLine("Reversed string: " & reversed)
  6.     End Sub
  7. Function ReverseString(input As String) As String
  8.         ' Base case: if the string is empty or has one character, return it as is
  9.         If input.Length <= 1 Then
  10.             Return input
  11.         Else
  12.             ' Recursive case: take the last character and append the reversed rest of the string
  13.             Return input(input.Length - 1) & ReverseString(input.Substring(0, input.Length - 1))
  14.         End If
  15.     End Function
  16. End Module
  17.  
Advertisement
Add Comment
Please, Sign In to add comment