Click here to Skip to main content
15,911,503 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to take the first 3 digits of the text file into another text file. My file is test.txt
195^20140212^0^H^000000^A
312^20140211^0^H^010000^A
312^20140211^0^H^020000^A
Where I only need to take the 195,312,312 in another text file. How can It be possible? I have tried the below but I am not able to save it to another text file.
C#
string test = @"\\Fdrtse\POI\Debopam\test.txt";
var text = File.ReadAllLines(test);

while (text != null) {
    foreach(var line in text) {
        string[] dataArray = line.Split('^');
    }
}

[Edit: MTHeffron - formatting]
Posted
Updated 12-Feb-14 8:36am
v2

1 solution

The while (text != null) condition is pointless, File.ReadAllLines() always returns an array of strings (possibly empty) unless it throws an exception.

After you Split() the line into dataArray, you should collect the dataArray[0] values into another List<string> and then at the completion of reading all of the input file, write the contents of that list to your output file, formatting appropriately for your purpose.
 
Share this answer
 
Comments
DEbopm 12-Feb-14 15:06pm    
Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900