Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Optimizing a method
Message
De
11/10/2010 15:55:36
 
 
À
11/10/2010 15:21:34
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:
01484791
Message ID:
01484797
Vues:
49
This message has been marked as the solution to the initial question of the thread.
>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?

I don't see where a stringbuilder could help. You are passing in two strings neither of which are modified by the method.....
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform