Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Need a reorg for .NET Framework 4
Message
De
25/07/2010 04:22:44
 
 
À
24/07/2010 20:20:22
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:
01473739
Vues:
45
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());
>Wait a minute, I've come up with another iteration of this and this time it will not remove your empty lines. Dunno why I didn't think of it earlier:
>
>
>string CRLF = "\r\n";
>string CR = "\r";
>string LF = "\n";
>string TestString = string.Format("Test this string. {0}It contains {1}{2}a blank line.", CRLF, CRLF, CRLF);
>// first replace the LFs
>TestString = TestString.Replace(LF, "");
>// then split on the CRs
>string[] lines = TestString.Split(CR.ToCharArray());
>
>for (int i = 0; i < lines.Length; i++)
>{
>	Debug.WriteLine(lines[i]);
>}
>
>
>The only thing I haven't tested is performance, but since you have the large strings, I'll leave that up to you.
>
>~~Bonnie
>
>
>
>
>>>Well, that is weird behavior (the thing with the LF). If your empty lines contain more than just a CRLF (like, say they contain a space or a tab), then my example will retain that "empty" line. But, anyway, it doesn't matter ... it sounds like you found a workable solution.
>>
>>Yes, it is just that I have to scan all the lines, after I have populated the string builder, to remove the LF character. Like I said, this does not happen on the first line but only on all upcoming ones.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform