Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to make a software that opens a text file and read all paragraphs from the file
and store all paragraphs in different variables. In my program paragraph are 3 fixed in count.

thanks.
Posted
Updated 26-Sep-12 23:25pm
v3

1 solution

Working on the assumption that a paragraph is separated by by a carriage return/line feed (char 13, 10) then it's quite simple.

C#
string filePath = @"c:\temp\doc.txt";
System.IO.FileStream fs = System.IO.File.OpenRead(filePath);
byte[] binaryData = new byte[fs.Length];
fs.Read(binaryData, 0, binaryData.Length);
string text = System.Text.Encoding.ASCII.GetString(binaryData);
string[] paragraphs = text.Split('\r').Select(m => m.Trim('\n')).ToArray();
 
Share this answer
 
Comments
Deepak_Shukla 27-Sep-12 6:18am    
Thanks
but not working
Stephen Hewison 27-Sep-12 6:29am    
The approach is sound. It's just the paragraph delimiter which might be wrong. You need to open you text file up in a hex editor. Look at the data in the file and find the characters which are common to where there are paragraphs and then adjust the code to split the text using that delimiter.
Stephen Hewison 27-Sep-12 6:29am    
P.s. if you tell someone something is not working. It might be a good idea to explain how it's not working.

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