473,811 Members | 3,521 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Search files for word replacement

14 New Member
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 1454
Ganon11
3,652 Recognized Expert Specialist
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
Sarahger9
14 New Member
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 Recognized Expert Specialist
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 Recognized Expert Moderator Specialist
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 Recognized Expert Moderator Expert
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
2218
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 jumped over the green fence then jumped into the web monitor. It was hurt so it jumped backwards and fell on its! -- The word we're searching for "web".
2
6483
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 TABLEORDERLINES ....
51
3927
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 DOCTYPE, <html>, <body>, etc.)? -- Harlan Messinger Remove the first dot from my e-mail address. Veuillez ôter le premier point de mon adresse de courriel.
0
2898
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: Sub replaceall() '
4
4841
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 way mean to secrife lots of time in asp.net. can any one give me such a expression in which i pass a data string and search word string and replace word string? if so plz help me out. i'm in badly need.
1
2176
by: ericswebber | last post by:
Case Insensitive Search with Sensitive Replace -------------------------------------------------------------------- Need a REGEX case insensitve search & replace where case of found string is mirrored in replacement string please. The above question is basically how does one perform a REGEX Case insensitve search and replace where the case of the found string is mirrored in the replacement string please.
3
9561
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 MusicAlbum let you find MP3 and other music files based on the singer and album name; DocAuthor let you find Office documents created by a certain user; DocAppName let you find files of a particular program, and so on. Indexing Service uses plug-ins...
2
5101
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, the string at the beginning explains what it does: '''A script for MS Word which does the following: 1) Assigns all Hebrew italic characters "Italic" character style. 2) Assigns all Hebrew bold characters "Bold" character style. 2) Assign all...
4
12454
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 this: can Access create the document and place it as an OLE object to the relevant table? Any help is greatly appreciated. Ricky
3
3563
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 other Windows flavors. Procedure: 1. Create a simple text file named test.txt. 2. Open the text file in a text editor and add a simple test word such as "blah" (not quotes).
0
9726
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10647
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10130
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7667
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5553
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4338
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.