Use StringBuilder to reverse a string : StringBuilder « Data Type « VB.Net Tutorial






Imports System

public class Test
   public Shared Sub Main
        Dim data As String = "abcdefgh"


        Dim objSB As New Text.StringBuilder
        Dim intLength As Integer = Len(data)
        Dim intChar As Integer
        Dim chr As Char
        Dim objTS As TimeSpan
        Dim dteStart As Date

        objSB.Capacity = intLength
        objSB.Append(data)
        dteStart = Now()

        For intChar = 0 To CInt(objSB.Length / 2 - 1)
            chr = objSB.Chars(intChar)
            objSB.Chars(intChar) = objSB.Chars(intLength - intChar - 1)
            objSB.Chars(intLength - intChar - 1) = chr
        Next

        objTS = Now().Subtract(dteStart)
        Console.WriteLine(objTS.ToString)
        Console.WriteLine(objSB.ToString)
   End Sub
   
End class
00:00:00
hgfedcba








2.40.StringBuilder
2.40.1.Demonstrating StringBuilder class constructors
2.40.2.StringBuilder: Insert string, Append and Replace
2.40.3.Append Char to StringBuilder
2.40.4.Demonstrating StringBuilder Append methods
2.40.5.StringBuilder AppendFormat
2.40.6.StringBuilder.AppendFormat: {0:D} is ${1: #,###.00}
2.40.7.Replace method.
2.40.8.Insert method of StringBuilder
2.40.9.StringBuilder: Length, Capacity, EnsureCapacity
2.40.10.Use StringBuilder Indexer
2.40.11.Demonstrating methods Insert and Remove of the StringBuilder class
2.40.12.Demonstrating method Replace
2.40.13.Use StringBuilder to reverse a string
2.40.14.StringBuilder.ToStrings
2.40.15.Performance difference between String and StringBuilder