Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Optimizing a method
Message
De
11/10/2010 15:21:34
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Optimizing a method
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01484791
Message ID:
01484791
Vues:
79
Is there a way to optimize this method?
        ' Equivalent of the AT() function in VFP
        ' expC1 Search for
        ' expC2 Search string
        ' expN1 Occurence
        ' expN2 Mode
        Public Function At(ByVal tcSearchFor As String, ByVal tcSearchIn As String, _
         ByVal tnOccurence As Integer, ByVal tnMode As Integer) As Integer
            Dim lnCounter As Integer = 0
            Dim lnLocation As Integer = 0
            Dim lnOccured As Integer = 0

            ' In this case we actually have to locate the occurence
            If tnMode = 1 Then
                lnLocation = 0
            Else
                lnLocation = tcSearchIn.Length
            End If

            ' Loop through the string and get the position of the required occurence
            For lnCounter = 1 To tnOccurence

                If tnMode = 1 Then
                    lnLocation = tcSearchIn.IndexOf(tcSearchFor, lnLocation)
                Else
                    lnLocation = tcSearchIn.LastIndexOf(tcSearchFor, lnLocation)
                End If

                If lnLocation < 0 Then
                    Exit For
                Else

                    ' Increment the occured counter based on the current mode we are in
                    lnOccured = lnOccured + 1

                    ' Check if this is the occurence we are looking for
                    If lnOccured = tnOccurence Then
                        Return lnLocation + 1
                    Else
                        If tnMode = 1 Then
                            lnLocation = lnLocation + 1
                        Else
                            lnLocation = lnLocation - 1
                        End If
                    End If

                End If

            Next

            Return 0
        End Function
The reason I ask is that I thought if using a StringBuilder would be better here. This is considering that I have some string of up to 20k to be passed here. so, if tcSearchFor is 20k, could this be a factor?
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform