Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Need a reorg for .NET Framework 4
Message
De
25/07/2010 15:03:59
 
 
À
25/07/2010 14:09:59
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:
01473780
Vues:
30
>>Now that we are clear on what Michel actually wants in the result the shortest solution seems to be:
>>string[] delimiters = new string[] { Environment.NewLine };   //may be safer than "\r\n" ?
>>string[] lines = TestString.Split(delimiters,StringSplitOptions.None);
>>Again I don't know if performance will be an issue but with 100000 lines of about 100 characters each this is still a sub-millisecond operation on my (average) machine. Ran out of ram trying a million lines tho :-{
>>Update: Your version using fluent syntax took pretty much the same time:
string[] lines = TestString.Replace("\r",String.Empty).Split("\n".ToCharArray());
>
>Using that approach, it resolves the issue.
>
>
>        ' Load the string into the string builder
>        ' expC1 String
>        Public Function LoadString(ByVal tcString As String) As Boolean
>            Dim lcDelimiter As String() = New String() {Environment.NewLine}
>
>            ' Make sure to clear the string builder
>            oStringBuilder.Length = 0
>
>            oStringBuilder.Append(tcString)
>
>            ' Initialize the array
>            oLine = oStringBuilder.ToString.Split(lcDelimiter, StringSplitOptions.None)
>
>            ' Count the number of lines
>            nLine = MemLines()
>
>            Return (True)
>        End Function
>
>        ' Return the number of lines in a string
>        Public Function MemLines() As Integer
>            Return oLine.Length
>        End Function
>
>        ' Return the specific line in a string
>        ' expN1 Line
>        Public Function MLine(ByVal tnLine As Integer) As Boolean
>
>            ' Reset the values
>            cLine = ""
>
>            ' If the value passed is smaller or eqaul to the number of lines
>            If tnLine - 1 <= nLine Then
>                cLine = oLine(tnLine - 1)
>            End If
>
>            Return True
>        End Function
>
>
>Before, I was using a direct reference to Environment.NewLine.ToCharArray in this line:
>
>
>            oLine = oStringBuilder.ToString.Split(Environment.NewLine.ToCharArray, StringSplitOptions.None)
>
>
>Now, I am using the String() approach. So, maybe this is why it didn't work before.

Using the char[] approach results in a string being written to the array for anything between a LF and CR (which if fine) but also for anything between CR and LF which, in the scenario, is an empty string. If you didn't have any genuinely empty strings between a LF and CR then using the StringSplitOptions.RemoveEmptyEntries would be fine but that wasn't the case.....

BTW - why bother using a StringBuilder in the LoadString() method ?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform