Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Need a reorg for .NET Framework 4
Message
De
23/07/2010 04:25:41
 
 
À
22/07/2010 18:03:04
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01473537
Message ID:
01473566
Vues:
60
This message has been marked as a message which has helped to the initial question of the thread.
>This code used to run extremely fast before I moved to .NET Framework 4.
>
>
>        ' Return the specific line in a string
>        ' expN1 Line
>        Public Function MLine(ByVal tnLine As Integer) As Boolean
>            Dim lnLocation As Integer = 0
>            Dim loStringBuilderValueAdjusted As StringBuilder = New StringBuilder()
>
>            ' If the line requested is greather than the number of lines
>            If tnLine > nLine Then
>                cLine = ""
>                Return True
>            End If
>
>            ' If we are requesting the first ilne
>            If tnLine = 1 Then
>
>                ' See if we have more than one line
>                If nLine > 1 Then
>                    cLine = Mid(oStringBuilder.ToString, 1, InStr(oStringBuilder.ToString, oApp.cCR) - 1)
>                Else
>                    cLine = oStringBuilder.ToString
>                End If
>
>            Else
>
>                ' Make sure we are able to find a carriage return
>                lnLocation = oApp.At(oApp.cCR, oStringBuilder.ToString, tnLine - 1)
>                If lnLocation > 0 Then
>                    loStringBuilderValueAdjusted.Append(Mid(oStringBuilder.ToString, _
>                     oApp.At(oApp.cCR, oStringBuilder.ToString, tnLine - 1) + 2))
>
>                    ' If this is not the last line
>                    lnLocation = InStr(loStringBuilderValueAdjusted.ToString, oApp.cCR)
>                    If lnLocation > 0 Then
>                        cLine = Mid(loStringBuilderValueAdjusted.ToString, 1, _
>                         InStr(loStringBuilderValueAdjusted.ToString, oApp.cCR) - 1)
>                    Else
>                        cLine = loStringBuilderValueAdjusted.ToString
>                    End If
>
>                Else
>                    cLine = oStringBuilder.ToString
>                End If
>            End If
>
>            Return True
>        End Function
>
>
>Basically, this code returns a specific line from a string. It was originally designed to match the MLine() function of VFP. But, now, under the .NET Framework 4.0, this runs extremely slow. The greater the number of lines in the string, the more the duration in time it takes to find the line.
>
>So, basically, I read a directory having 1000 files. This goes into a string. Then, I use the number of carriage returns to locate the start of the string and get the line associated to it. But, I have to find another approach. Does anyone would have a better function to return a specific line from a string?

As per Bonnie Split() will be quicker. So (if s is the string):
Function MLine(ByVal line As Integer, ByRef cLine As String) As Boolean
         Dim array As String() = s.Split(ControlChars.Cr)
        If line > array.Length Then
            cLine = String.Empty
            Return False
        Else
            cLine = array(line)
            Return True
        End If
    End Function
(maybe needs a check for negative line)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform