Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Need a reorg for .NET Framework 4
Message
De
23/07/2010 00:42:21
 
 
À
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:
01473549
Vues:
75
This message has been marked as the solution to the initial question of the thread.
I wonder if using split will be any faster? Something like this (off the top of my head, untested):
string[] lines = oStringBuilder.ToString.Split(oApp.cCR)
cLine = lines[tnLine]
~~Bonnie



>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?
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform