Suraj Binorkar Suraj Binorkar - 1 year ago 101
C# Question

Read specific word from text file in C# windows application

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 :)

Answer Source

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];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download