0
votes

I am trying to read specific word from text file I know its easy and I have done but I need to read from sentence i.e. if file contain WC|110916|F-12003||ZET5.4|27019570 then i need to pic "27019570" this specific word, I did with substring(26,8) splitting with characters and its works but every line not having specific size/length so splitting words is not proper solution for this. In short I need to know how do i check (|) this character and its position on every sentence which includes in text file.

Thanks in Advance :)

2
is there multi line sentences in your text file?Damith
yes, but now problem solved thanks for your response :)Suraj Binorkar

2 Answers

0
votes

you can split each line by '|' character . it returns an array then you can select the desired index.

var textFromFile = "WC|110916|F-12003||ZET5.4|27019570";
var goalText = textFromFile.Split('|')[5];
0
votes

if you're using .NET 3.5 or higher, it's easy using LINQ with File.ReadAllLines

string fullFilePath = @"C:\ed\cc\filename.txt";

List<string> items = File.ReadAllLines(fullFilePath ).Select(line=>line.Split('|').Last()).ToList();