944,160 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2600
  • C++ RSS
Aug 16th, 2006
0

Search a txt file for words

Expand Post »
hi all , i have a txt file called myfile.txt , i want to open this file and search for the following
" this page is good/"

if i find this i want to read every thing after "/" until i reach <b> so for example

this page is good/so i want to copy this<b>

dont mind my question but i really dont know much in C++


thanks for your great help
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
taha54 is offline Offline
3 posts
since Aug 2006
Aug 16th, 2006
0

Re: Search a txt file for words

any help???
Reputation Points: 10
Solved Threads: 0
Newbie Poster
taha54 is offline Offline
3 posts
since Aug 2006
Aug 16th, 2006
0

Re: Search a txt file for words

1. Open file
2. Retrieve data in a string
3. Compare
4. Once you find a match then read again till you find first <b>
Reputation Points: 197
Solved Threads: 12
Junior Poster
Grunt is offline Offline
147 posts
since Jul 2006
Aug 16th, 2006
0

Re: Search a txt file for words

i need the code for that , i really dont know alot in C++
Reputation Points: 10
Solved Threads: 0
Newbie Poster
taha54 is offline Offline
3 posts
since Aug 2006
Aug 16th, 2006
1

Re: Search a txt file for words

We really don't like to write whole programs or routines for people. Here's a quick overview with a little more detail than p;rovided by Grunt. As you can tell, there are several choices you will have to make depending on what you know and don't know.

The phrase you are looking for is called a string. The file you are searching can be opened and read in as a sequence of strings or as a single string. You will then need to search for the string(s) from the file for the desired string. If found, the desired string is called a substring of the whole string. There are several ways to search for a substring depending on the type of string you use. You could use strstr() if you use C style strings, and I'm sure that the STL library will have functions to search for substrings as well, either in the string library itself or in the algorithm library. It would also be instructive to write your own function to familiarize yourself with the workings of strings. Last, but not least, if you aren't familiar with the concept of strings at all, then this project is beyond your scope of programming at this point and you should set your sights a little lower for now---like learning about strings, working with files, etc.
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005
Aug 16th, 2006
0

Re: Search a txt file for words

Show some effort. I don't think anyone here will give you code this way.
Reputation Points: 197
Solved Threads: 12
Junior Poster
Grunt is offline Offline
147 posts
since Jul 2006
Aug 16th, 2006
0

Re: Search a txt file for words

Look into string methods, like .find(), .delete(), etc.
Moderator
Reputation Points: 3281
Solved Threads: 896
Posting Sage
WaltP is offline Offline
7,749 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: local variables
Next Thread in C++ Forum Timeline: C++ Refresher Question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC