Note that there are some explanatory texts on larger screens.

plurals
  1. POTranspose content of file
    text
    copied!<p>I have a txt file looking like this:</p> <pre><code>1 5 7 5 4 8 19 6 23 56 78 9 </code></pre> <p>I want to read all these values and write them to new file, but with different order.</p> <p>Output file should look like this:</p> <pre><code>1 4 23 5 8 56 7 19 78 5 6 9 </code></pre> <p>Right now I am trying to read everything into array, but I am not sure how to handle this data later...</p> <pre><code>string line; using (StreamReader sr = new StreamReader(@"C:\Users\as\Desktop\file\1.txt", Encoding.Default)) { line = sr.ReadToEnd(); string[] lines = line.Split('\n'); string newLine = lines[0].ToString(); } </code></pre> <p>My input file can have even up to 400000 columns.</p> <p>EDIT 2:</p> <p>I tried sth like this, but still not working, any suggestions?</p> <pre><code>using (StreamReader sr = new StreamReader(@"C:\Users\as\Desktop\files\1.txt", Encoding.Default)) { List&lt;string&gt; list = new List&lt;string&gt;(); while ((line = sr.ReadLine()) != null) { list.Add(line); } int valuesNumber = list[0].Split(' ').Count(); List&lt;string&gt; final = new List&lt;string&gt;(); for (int j = 0; j &lt; valuesNumber ; j++) { for (int i = 0; i &lt; list.Count; i++) { string[] stringArray = list[i].Split(' '); final .Add(stringArray[j]); } } using (StreamWriter writer = new StreamWriter(@"C:\Users\as\Desktop\files\2.txt", true)) { foreach (string item in result) { writer.WriteLine(item.ToString()); } } } </code></pre> <p>But I still get every number under previous one, like this:</p> <pre><code>1 4 23 5 8 56 7 19 78 5 6 9 </code></pre>
 

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