Click here to Skip to main content
15,898,981 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
I have a doc file, which contains many articles, and each article is differentiate by 4 enters...
I wan to separate each article, i'm using this code..


C#
string[] seperator=new string[] {"\n\n\n\n"};
foreach(word.range range in doc.StoryRanges)
{
  string[] files = richTextBox1.Text.Split(seperator, StringSplitOptions.None);
}


but it's not working...
please help me with this..
Posted
Updated 17-Jun-14 22:37pm
v3
Comments
Vedat Ozan Oner 18-Jun-14 4:39am    
what do you mean by 'not working'? which part doesn't work? you can use your debugger. f9 breakpoint. f10 step over etc.
Richard MacCutchan 18-Jun-14 4:39am    
What does "not working" mean?
ShobuGpta 18-Jun-14 4:48am    
means it's not separating the file, variable file is getting whole text of the file in single a array only...
Vedat Ozan Oner 18-Jun-14 5:18am    
many possibility. your text may not contain the pattern you expect. the text you try to split may not be the text you assume, etc. best, use your debugger to see what happens.
ShobuGpta 18-Jun-14 5:21am    
i first loaded whole file in a richtextbox and then used the same code for the richtextbox and the code is working now... I still dont get it, why it's working for richtextbox not if i direct access the file... Can you please explain it to me

1 solution

"i first loaded whole file in a richtextbox and then used the same code for the richtextbox and the code is working now... I still dont get it, why it's working for richtextbox not if i direct access the file... Can you please explain it to me"


Pretty simple: the Text property of a RichTextBox returns the content without any formatting information. A raw DOC file doesn't: it contains formatting information, and very likely does not use a single '\n' on it's own to indicate a line break, or "\n\n\n\n" to indicate four in a sequence.

There is an easy way to check: load your file in a text editor that doesn't interpret the formatting codes (Notepad, or I use PSPad) and look at it. Find the end of the first article, and see what is there. It may help if you use a Hex Editor instead of a text editor, if teh file content contains binary info.
 
Share this answer
 

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