Reverse String. A String contains individual characters. The order of these characters can be reversed. But we cannot change a string directly.
Implementation notes. In VB.NET we reverse a string using the ToCharArray function. We then use the Array.Reverse Sub, and finally the String constructor.
An example. In Reverse() we store the value returned by ToCharArray in a local variable. Next pass that variable to the Array.Reverse subroutine.
Info Reverse internally rearranges the characters in the array to be in the opposite order.
Finally You must invoke the String constructor. This converts the reversed character array back into a string.
''' Reverse input string.
''' </summary>FunctionReverse(ByVal value As String) As String
' Convert to char array.
Dim arr() As Char = value.ToCharArray()
' Use Array.Reverse function.
' Construct new string.
Return New String(arr)
Interviews. Readers have commented that in interview questions, the classic question of writing a method to reverse a string often have some constraints.
Info For example, you might be required not to call methods such as Array.Reverse.
However Even with these constraints, you would likely need to use the String constructor or possibly ToCharArray.