473,396 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Search files for word replacement

Hi,
I'm working on a project that searches one file for words and their replacements found in another file. I'm stuck at the beginning. I think, I need to put the words in the file in an array so I can search the array, but I'm not sure how to do this. If someone could help me get started I can work on the rest of the code.
Thanks
Oct 4 '07 #1
5 1435
Ganon11
3,652 Expert 2GB
I don't really understand your program: could you elaborate a bit more? I think it might be good if we could see an example of these two text files.
Oct 4 '07 #2
Ok, sorry for the confusion. The one file is just a text file, a short story that I have to search for words in. The other file, is another text file, that looks like this:

Harry Harold
scar mark
mom mum
magic mystery
I Me

The first column is the words I'm looking for, the second column is the word I need to replace the first column with.
If you could get me started I would greatly appreciate it. Right now, all my code does is open both files and count the words in the text file.

Thanks
Oct 4 '07 #3
Ganon11
3,652 Expert 2GB
To prevent this from getting really long, I would look at the words one at a time. So you take one word from your story file. If you can find that word in your replacement file, then replace it. If you don't find it in the replacement file, don't do anything about it. Once you're done with a word, write it to a new file. At the end, your new file will have the 'updated' story.
Oct 4 '07 #4
sicarie
4,677 Expert Mod 4TB
Sarahger9-

I changed your thread title to be a bit more descriptive, please try to do so as well in the future, it will help get your question answered more promptly (as people who have experience with your issue will then be able to see that).
Oct 5 '07 #5
weaknessforcats
9,208 Expert Mod 8TB
Take a deep breath and slow down.

From what I read, you have been coding. To do that, it means you have written down your method and are just implementing it. I going to take a chance here and guess that you haven't written down the steps you need to follow to achieve this. If this guess is correct then your coding just lurches around until it kinda mabybe works.

Define you algorithm:
1) read data file record in memory
2) for each word in the record, search the other file for a replacement.
3) if found, replace the word in the record in memory
etc...
Oct 5 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Sharif T. Karim | last post by:
I am trying to do the following with my search script that looks for records in a mysql table. The following is an example of what I am trying to do. Text being searched: -- The brown fox...
2
by: Babu Mannaravalappil | last post by:
Hi, I want to replace some words in my text files (actually transpose). For example, I have a whole lot of expressions (words) in my files as follows: TABLECUSTOMERS TABLEORDERS...
51
by: Harlan Messinger | last post by:
Are files referenced in LONGDESC attributes supposed to be pure text; can or should they have either block or inline HTML tags; can or should they be set up as a fully W3C compliant web page (with...
0
by: David Krmpotic | last post by:
Regards, I need a little explanation in converting word VB macros to charp code! first, I recorded simple macro which replaces every occurence of one word in whole document (is it?) , here:...
4
by: lucky | last post by:
hi there!! i'm looking for a code snipett wich help me to search some words into a particular string and replace with a perticular word. i got a huge data string in which searching traditional...
1
by: ericswebber | last post by:
Case Insensitive Search with Sensitive Replace -------------------------------------------------------------------- Need a REGEX case insensitve search & replace where case of found string is...
3
by: Chung Leong | last post by:
Here's the rest of the tutorial I started earlier: Aside from text within a document, Indexing Service let you search on meta information stored in the files. For example, MusicArtist and...
2
by: Ola K | last post by:
Hi guys, I wrote a script that works *almost* perfectly, and this lack of perfection simply puzzles me. I simply cannot point the whys, so any help on it will be appreciated. I paste it all here,...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
3
by: =?Utf-8?B?UGVycmlud29sZg==?= | last post by:
Not sure where to post this... Found some interesting behavior in Windows Search (Start =Search =All files and folders =search for "A word or phrase in the file:"). This applies to XP and maybe...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.