Click here to Skip to main content
15,903,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to display only some portion of the .txt file, in text format means it should display some characters or words of the file, that is if i enter starting position & ending position then it should display the words between the entered starting position & ending position & if i enter a word, it should display all the rest of the file starting from that entered word. How can i do it in vc++ (mfc)?

Thanks in advance........
Posted
Updated 29-Mar-11 22:25pm
v2
Comments
Sergey Alexandrovich Kryukov 30-Mar-11 3:04am    
This Question does not provide sufficient specification on what and how it should be done, so it is not possible to give a single definitive Answer.
--SA

How do you expect anyone to answer that?

What kind of file? Text? Word DOC? Excel, Database, Picture, video, executable, DLL, MP3, DWG, OldUncleTomCobley, or propriartory?

How do you want to display it? Text? Binary, Formatted, Picture, Mayan Knotted rope, Egyptian Hieroglyphics?

You need to try to give enough information that at least we can make an informed response - even if we can't help.

And it would help your cause if you showed that you had at least tried to do some of it yourself...


"it's a .txt file & want to display in text format"


So, the first thing to do is to decide how you will decide which part to display.

If you want whole lines, displaying (say) lines 100 - 200 only? If so then:
string[] lines = Files.ReadAllLines(path);
int startLine = 100;
int endLine = 200;
int count = endLine - startLine + 1;
string[] viewThese = new string[count];
Array.Copy(lines, startLine, viewThese, 0, count);
MyTextBox.Lines = viewThese;


If you don't want whole lines, then the principle is the same, but you have to do a bit more work.
 
Share this answer
 
v2
Comments
virus131 30-Mar-11 4:13am    
it's a .txt file & want to display in text format
OriginalGriff 30-Mar-11 5:04am    
Answer updated
virus131 30-Mar-11 6:04am    
i want it in vc++ (mfc), can u please give me solution in mfc for the same?
virus131 31-Mar-11 3:59am    
i want it in vc++ (mfc), can u please give me solution in mfc for the same?
If 'starting' and 'ending' position are in bytes, then your task is simple: use fseek[^] to move the file pointer and read ('ending'-'starting' + 1) bytes and finally show them (a bit more complex if you want to show just complete words).

If 'starting' and 'ending' mean 'starting word number' and 'ending word number' then you have to build a simple scanner reading a token (word) at time, discarding all the words preceding 'starting' and proceding until 'ending' is reached.

:-)
 
Share this answer
 
what't the type of your file?Is it .txt or .doc?which portion of the file do you want to display?Some Lines or Some words?Y should in detail discribe your problem
 
Share this answer
 
Comments
virus131 30-Mar-11 4:11am    
it's a .txt file and want to display in text format

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