Jump to content



MEGA BUG / FLOW για το .ΝΕΤ 2.0, 3.0, 3.5 και 4.0!!!


G0D

Recommended Posts

Πιο συγκεκριμένα το σφάλμα έχει να κάνει με την αρχικοποίηση πινάκων τύπου string κατά την φορτωσή τους απο δεδομένα μέσω ενός StreamWriter/TextWriter.

Το πρόβλημα που παρατηρήθηκε είναι ότι εάν έχουμε δημιουργήσει και αρχικοποιήσει έναν πίνακα τύπου string και ύστερα φορτώσουμε δεδομένα μέσω ενός StreamWriter τότε για μη προφανή λόγω ο πίνακας αλλάζει διαστάσεις και συρικνώνεται μετά την φόρτωσή του με δοδομένα!

Με πιο προσεκτική παρατήρηση βρέθηκε ότι ο πίνακας αρχικοποιείται και πάλι με νέα στοιχεία και διαστάσεις γιατί γίνεται μια "σιωπηλή" κλήση του κατασκευαστή του πριν την φόρτωση των δεδομένων στο split!

Όπως καταλαβαίνεται αυτό αλλάζει τη λογική και την αρχιτεκτονική μέσα στο flaw του προγραμματισμού και δεν είναι διόλου ευπρόσδεκτο.

Θα γίνουν έρευνες για το αν αυτό συμβαίνει και με άλλα μέρη του .NET και αν αποδειχτεί ότι το bug είναι γενικευμένο μιλάμε για μια πλήρη παρανόηση στη λογική του δομημένου προγραμματισμού επάνω σε .NET.

Το ιδαίτερο bug έχει ήδη καταχωρυθεί προς ενημέρωση της Microsoft αλλά κανείς δε δείχνει να έχει ενδιαφερθεί μέχρι τώρα...

Link to comment
Share on other sites

Ακόμα και έτσι, μια χαρά δουλεύει ο κώδικας που δίνεις :

[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] button1_Click([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sender, [/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]EventArgs[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] e)
{
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] theString = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][] StringArray = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][5];
System.IO.[/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]TextReader[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] txtReader = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.IO.[/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]StreamReader[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]@"c:\aa.txt"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]); [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// 4 "|"
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Array[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Clear(StringArray, 0, 4);
theString = txtReader.ReadLine();
txtReader.Close();
StringArray = theString.Split([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]'|'[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] result = [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// flow out of the boundaries exception! - length 4 5!!!
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] i = 0; i < 5; i++)
{
result += i.ToString() + [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]": "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + StringArray[i] + [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"\r\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
}
[/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]MessageBox[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Show(result);
}
[/SIZE]

Και σε 2.0, και 3.5 και 4.0

post-4796-1416075023,8028_thumb.png

Link to comment
Share on other sites

Ακόμα και έτσι, μια χαρά δουλεύει ο κώδικας που δίνεις :

[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] button1_Click([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sender, [/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]EventArgs[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] e)
{
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] theString = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][] StringArray = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][5];
System.IO.[/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]TextReader[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] txtReader = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.IO.[/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]StreamReader[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]@"c:\aa.txt"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]); [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// 4 "|"
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Array[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Clear(StringArray, 0, 4);
theString = txtReader.ReadLine();
txtReader.Close();
StringArray = theString.Split([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]'|'[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] result = [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// flow out of the boundaries exception! - length 4 5!!!
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] i = 0; i < 5; i++)
{
result += i.ToString() + [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]": "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + StringArray[i] + [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"\r\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
}
[/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]MessageBox[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Show(result);
}
[/SIZE]

Και σε 2.0, και 3.5 και 4.0

Με 4 ορίσματα όχι 4 pipes!!!

Try it!

Link to comment
Share on other sites

Λογικό είναι που κάνει αυτό που λες. Άκου τι γίνεται: ο πίνακας StringArray είναι μία μεταβλητή τύπου string[]. Όταν εσύ του λές string[] StringArray = new string[5]; τότε αυτό σημαίνει ότι αυτό το αντικείμενο αρχικοποιείται με έναν κενό πίνακα από strings. Ομοίως όταν του δίνεις StringArray = theString.Split('|'); αυτό σημαίνει ότι η μεταβλητή StringArray δεν θα δείχνει στο κενό "new string[5]" αλλά στο νέο αντικείμενο που θα προέλθει από την εντολή "theString.Split('|');. Εσύ δεν του λες εδώ να προσθέσει τα strings μέσα στον πίνακα, αλλά του αντικαθιστάς τον πίνακα με έναν καινούριο. Οπότε δεν υπάρχει πρόβλημα.

Link to comment
Share on other sites

H string.Split επιστρέφει έναν new String[]. Reflector is your friend :

[[URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Runtime.InteropServices.ComVisibleAttribute/.ctor(Boolean)"]ComVisible[/URL]([COLOR=#800000]false[/COLOR])][COLOR=#1000a0]public[/COLOR] [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String"]string[/URL][] [B][URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String/Split(Char%5b%5d,Int32,System.StringSplitOptions):String%5b%5d"]Split[/URL][/B]([URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Char"]char[/URL][] separator, [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"]int[/URL] count, [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.StringSplitOptions"]StringSplitOptions[/URL] options){    [COLOR=#1000a0]if[/COLOR] (count < [COLOR=#800000]0[/COLOR])    {        [COLOR=#1000a0]throw[/COLOR] [COLOR=#1000a0]new[/COLOR] [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.ArgumentOutOfRangeException/.ctor(String,String)"]ArgumentOutOfRangeException[/URL]([COLOR=#800000]"count"[/COLOR], [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Environment"]Environment[/URL].[URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Environment/GetResourceString(String):String"]GetResourceString[/URL]([COLOR=#800000]"ArgumentOutOfRange_NegativeCount"[/COLOR]));    }    [COLOR=#1000a0]if[/COLOR] ((options < [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.StringSplitOptions"]StringSplitOptions[/URL].[URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.StringSplitOptions/None"]None[/URL]) || (options > [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.StringSplitOptions"]StringSplitOptions[/URL].[URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.StringSplitOptions/RemoveEmptyEntries"]RemoveEmptyEntries[/URL]))    {        [COLOR=#1000a0]throw[/COLOR] [COLOR=#1000a0]new[/COLOR] [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.ArgumentException/.ctor(String)"]ArgumentException[/URL]([URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Environment"]Environment[/URL].[URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Environment/GetResourceString(String,Object%5b%5d):String"]GetResourceString[/URL]([COLOR=#800000]"Arg_EnumIllegalVal"[/COLOR], [COLOR=#1000a0]new[/COLOR] [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Object"]object[/URL][] { ([URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"]int[/URL]) options }));    }    [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Boolean"]bool[/URL] [B]flag[/B] = options == [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.StringSplitOptions"]StringSplitOptions[/URL].[URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.StringSplitOptions/RemoveEmptyEntries"]RemoveEmptyEntries[/URL];    [COLOR=#1000a0]if[/COLOR] ((count == [COLOR=#800000]0[/COLOR]) || (flag && ([COLOR=#1000a0]this[/COLOR].[URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String/property:Length:Int32"]Length[/URL] == [COLOR=#800000]0[/COLOR])))    {        [COLOR=#1000a0]return[/COLOR] [COLOR=#1000a0][B]new[/B][/COLOR] [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String"]string[/URL][[COLOR=#800000]0[/COLOR]];    }    [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"]int[/URL][] [B]sepList[/B] = [COLOR=#1000a0]new[/COLOR] [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"]int[/URL][[COLOR=#1000a0]this[/COLOR].[URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String/property:Length:Int32"]Length[/URL]];    [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"]int[/URL] [B]numReplaces[/B] = [COLOR=#1000a0]this[/COLOR].[URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String/MakeSeparatorList(Char%5b%5d,Int32%5b%5d&):Int32"]MakeSeparatorList[/URL](separator, [COLOR=#1000a0]ref[/COLOR] sepList);    [COLOR=#1000a0]if[/COLOR] ((numReplaces == [COLOR=#800000]0[/COLOR]) || (count == [COLOR=#800000]1[/COLOR]))    {        [COLOR=#1000a0]return[/COLOR] [COLOR=#1000a0][B]new[/B][/COLOR] [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String"]string[/URL][] { [COLOR=#1000a0]this[/COLOR] };    }    [COLOR=#1000a0]if[/COLOR] (flag)    {        [COLOR=#1000a0]return[/COLOR] [B][COLOR=#1000a0]this[/COLOR].[/B][URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String/InternalSplitOmitEmptyEntries(Int32%5b%5d,Int32%5b%5d,Int32,Int32):String%5b%5d"][B]InternalSplitOmitEmptyEntries[/B][/URL](sepList, [COLOR=#800000]null[/COLOR], numReplaces, count);    }    [COLOR=#1000a0]return[/COLOR] [B][COLOR=#1000a0]this[/COLOR].[/B][URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String/InternalSplitKeepEmptyEntries(Int32%5b%5d,Int32%5b%5d,Int32,Int32):String%5b%5d"][B]InternalSplitKeepEmptyEntries[/B][/URL](sepList, [COLOR=#800000]null[/COLOR], numReplaces, count);}


[COLOR=#1000a0]private[/COLOR] [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String"]string[/URL][] [B][URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String/InternalSplitOmitEmptyEntries(Int32%5b%5d,Int32%5b%5d,Int32,Int32):String%5b%5d"]InternalSplitOmitEmptyEntries[/URL][/B]([URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"]int[/URL][] sepList, [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"]int[/URL][] lengthList, [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"]int[/URL] numReplaces, [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"]int[/URL] count){ [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"]int[/URL] [B]num[/B] = (numReplaces < count) ? (numReplaces + [COLOR=#800000]1[/COLOR]) : count; [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String"][B]string[/B][/URL][B][] strArray = [COLOR=#1000a0]new[/COLOR] [/B][URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String"][B]string[/B][/URL][B][[/B][B]num[/B][B]];[/B] [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"]int[/URL] [B]startIndex[/B] = [COLOR=#800000]0[/COLOR]; [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"]int[/URL] [B]num3[/B] = [COLOR=#800000]0[/COLOR]; [COLOR=#1000a0]for[/COLOR] ([URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"]int[/URL] [B]i[/B] = [COLOR=#800000]0[/COLOR]; (i < numReplaces) && (startIndex < [COLOR=#1000a0]this[/COLOR].[URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String/property:Length:Int32"]Length[/URL]); i++) { [COLOR=#1000a0]if[/COLOR] ((sepList[i] - startIndex) > [COLOR=#800000]0[/COLOR]) { strArray[num3++] = [COLOR=#1000a0]this[/COLOR].[URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String/Substring(Int32,Int32):String"]Substring[/URL](startIndex, sepList[i] - startIndex); } startIndex = sepList[i] + ((lengthList == [COLOR=#800000]null[/COLOR]) ? [COLOR=#800000]1[/COLOR] : lengthList[i]); [COLOR=#1000a0]if[/COLOR] (num3 == (count - [COLOR=#800000]1[/COLOR])) { [COLOR=#1000a0]while[/COLOR] ((i < (numReplaces - [COLOR=#800000]1[/COLOR])) && (startIndex == sepList[++i])) { startIndex += (lengthList == [COLOR=#800000]null[/COLOR]) ? [COLOR=#800000]1[/COLOR] : lengthList[i]; } [COLOR=#1000a0]break[/COLOR]; } } [COLOR=#1000a0]if[/COLOR] (startIndex < [COLOR=#1000a0]this[/COLOR].[URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String/property:Length:Int32"]Length[/URL]) { strArray[num3++] = [COLOR=#1000a0]this[/COLOR].[URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String/Substring(Int32):String"]Substring[/URL](startIndex); } [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String"][B]string[/B][/URL][B][] strArray2 = [/B][B]strArray[/B][B];[/B] [COLOR=#1000a0]if[/COLOR] (num3 != num) { [B]strArray2[/B][B] = [COLOR=#1000a0]new[/COLOR] [/B][URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String"][B]string[/B][/URL][B][[/B][B]num3[/B][B]];[/B] [COLOR=#1000a0]for[/COLOR] ([URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"]int[/URL] [B]j[/B] = [COLOR=#800000]0[/COLOR]; j < num3; j++) { strArray2[j] = strArray[j]; } } [COLOR=#1000a0]return[/COLOR] strArray2;}

[COLOR=#1000a0]private[/COLOR] [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String"]string[/URL][] [B][URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String/InternalSplitKeepEmptyEntries(Int32%5b%5d,Int32%5b%5d,Int32,Int32):String%5b%5d"]InternalSplitKeepEmptyEntries[/URL][/B]([URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"]int[/URL][] sepList, [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"]int[/URL][] lengthList, [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"]int[/URL] numReplaces, [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"]int[/URL] count){    [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"]int[/URL] [B]startIndex[/B] = [COLOR=#800000]0[/COLOR];    [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"]int[/URL] [B]index[/B] = [COLOR=#800000]0[/COLOR];    count--;    [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"]int[/URL] [B]num3[/B] = (numReplaces < count) ? numReplaces : count;    [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String"][B]string[/B][/URL][B][] strArray = [COLOR=#1000a0]new[/COLOR] [/B][URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String"][B]string[/B][/URL][B][[/B][B]num3[/B][B] + [COLOR=#800000]1[/COLOR]];[/B]    [COLOR=#1000a0]for[/COLOR] ([URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"]int[/URL] [B]i[/B] = [COLOR=#800000]0[/COLOR]; (i < num3) && (startIndex < [COLOR=#1000a0]this[/COLOR].[URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String/property:Length:Int32"]Length[/URL]); i++)    {        strArray[index++] = [COLOR=#1000a0]this[/COLOR].[URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String/Substring(Int32,Int32):String"]Substring[/URL](startIndex, sepList[i] - startIndex);        startIndex = sepList[i] + ((lengthList == [COLOR=#800000]null[/COLOR]) ? [COLOR=#800000]1[/COLOR] : lengthList[i]);    }    [COLOR=#1000a0]if[/COLOR] ((startIndex < [COLOR=#1000a0]this[/COLOR].[URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String/property:Length:Int32"]Length[/URL]) && (num3 >= [COLOR=#800000]0[/COLOR]))    {        strArray[index] = [COLOR=#1000a0]this[/COLOR].[URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String/Substring(Int32):String"]Substring[/URL](startIndex);        [COLOR=#1000a0]return[/COLOR] strArray;    }    [COLOR=#1000a0]if[/COLOR] (index == num3)    {        strArray[index] = [URL="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String/Empty"]Empty[/URL];    }    [COLOR=#1000a0]return[/COLOR] strArray;}

Συνεπώς δεν είναι bug του .NET απλά δεν δουλεύει όπως θα ήθελες. Φτιάξε την δικιά σου Split ή κάνε αυτό που λέει ο Wizz ( :hug:) στο ποστ #2

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.