Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Optimized way to transfer from String to StringBuilder
Message
De
03/02/2014 23:51:50
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01593079
Message ID:
01593089
Vues:
33
>Made a quick google search and found this discussion (I was thinking along the same lines)
>
>http://stackoverflow.com/questions/12261344/fastest-search-method-in-stringbuilder

Thanks, I took a look at it but this is not exactly what I want.

Here is what I have so far:
            ' Check for the last occurrence
            If Mid(loStringBuilder.ToString, loStringBuilder.Length - lcWord.Length) = "." + lcWord Then
                loStringBuilder.Remove(loStringBuilder.Length - 1 - lcWord.Length, lcWord.Length)
                loStringBuilder.Append("[" + lcWord + "] ")
            End If

            ' Check for the first occurrence
            If Mid(loStringBuilder.ToString, 1, lcWord.Length + 1) = lcWord + "." Then
                loStringBuilder = oApp.StuffFromStringBuilder(loStringBuilder, 1, 1, "[")
                loStringBuilder = oApp.StuffFromStringBuilder(loStringBuilder, lcWord.Length + 2, 1, "]")
            End If
The Stuff is an equivalent of VFP Stuff command:
    ' Equivalent of VFP Stuff but for a StringBuilder()
    ' expO1 StringBuilder
    ' expN1 Start of replacement
    ' expN2 Number of characters to be replaced
    ' expC2 Replacement character expression
    Public Function StuffFromStringBuilder(ByVal toStringBuilder As StringBuilder, ByVal tnStartReplacement As Integer, _
     ByVal tnCharacterReplaced As Integer, ByVal tcReplacement As String) As StringBuilder

        ' First remove the characters specified in nCharacterReplaced
        If tnCharacterReplaced <> 0 Then
            toStringBuilder.Remove(tnStartReplacement - 1, tnCharacterReplaced)
        End If

        ' Now Add the new string at the right location
        ' sb.Insert(0,cExpression,nTimes)
        toStringBuilder.Insert(tnStartReplacement - 1, tcReplacement)

        Return toStringBuilder
    End Function
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform