Note that there are some explanatory texts on larger screens.

plurals
  1. POError in parsing text file
    primarykey
    data
    text
    <p>Guys, I have an error with my code and i do not understand why, here's my code:</p> <pre><code>private void Parsing_String(string filename) { int outValue; int[][] number = new int[26][]; List&lt;Row&gt; list = new List&lt;Row&gt;(); //StreamReader freader = File.OpenText(filename); var parsed = File.ReadLines(filename) .Select(line =&gt; line.Split(' ') .Where(IsInteger) .Select(s =&gt; int.Parse(s)) .ToArray()) .ToArray(); foreach (String str in File.ReadLines(filename)) { String[] strCols = str.Split(' '); /*for (int i = 0; i &lt; 26; i++) { number[i] = new int[strCols.Length]; for (int j = 0; j &lt; strCols.Length; j++) { number[i][j] = int.TryParse(strCols[j].Substring(2), out outValue) ? outValue : 0; listBox2.Items.Add(number[i][j]); } }*/ list.Add(new Row() { Column1 = int.TryParse(strCols[0].Substring(2), out outValue) ? outValue : 0, Column2 = int.TryParse(strCols[1].Substring(2), out outValue) ? outValue : 0, Column3 = int.TryParse(strCols[2].Substring(2), out outValue) ? outValue : 0, Column4 = int.TryParse(strCols[3].Substring(2), out outValue) ? outValue : 0, Column5 = int.TryParse(strCols[4].Substring(2), out outValue) ? outValue : 0, Column6 = int.TryParse(strCols[5].Substring(2), out outValue) ? outValue : 0, }); } dg.ItemsSource = list; label3.Content = number[1][0]; label4.Content = number[0][1]; int kali = number[0][0] * number[0][1]; label2.Content = kali; } static bool IsInteger(string possibleInt) { int k; return int.TryParse(possibleInt, out k) ? k : 0; } public class Row { public int Column1 { get; set; } public int Column2 { get; set; } public int Column3 { get; set; } public int Column4 { get; set; } public int Column5 { get; set; } public int Column6 { get; set; } } #endregion } </code></pre> <p>} // Here The Text File Sample 10192 20351 30473 40499 50449 60234 10192 20207 30206 40203 50205 60226 10192 20252 30312 40376 50334 60252 10192 20271 30332 40405 50209 60234</p> <p>can someone show me what i am doing wrong?</p> <p>what i'm wanting to do is, i have a text file containing a number, i want to parse it, and put each number in an array so i can access it easily. Is my code effective enough?</p> <p>thanks, alot for a suggestion.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload