Reverse a string in VB.NET





4
Date Submitted Sat. Sep. 9th, 2006 9:22 PM
Revision 1 of 1
Helper jbplou
Tags String | VB.NET
Comments 2 comments
This function provides the reverse of a string. It is constructed using string builder because strings in .NET are immutable, while stringbuilders are not. Therefore large strings could be slow to reverse if a regular string was used for the working value that is returned.

    'Provides the reverse of a passed in string
    Private Function Reverse(ByVal value As String) As String
        If value.Length > 1 Then
            Dim workingValue As New System.Text.StringBuilder
            For position As Int32 = value.Length - 1 To 0 Step -1
                workingValue.Append(value.Chars(position))
            Next
            Return workingValue.ToString
        Else
            Return value
        End If
    End Function
 

Jeff B

Comments

Comments Another way...
Mon. Sep. 11th, 2006 9:44 AM    Newbie RobK410
Comments One more way
Wed. Sep. 20th, 2006 10:55 PM    Newbie gfast1

Voting