473,394 Members | 2,031 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,394 software developers and data experts.

I want to find out word from string and replace with new word.

I want to write a code which replace words from string.without use of string function in c language.

Example str = "This is string" remove "is" from string and replace with "was".
so, finally str = "This was string".
Oct 4 '08 #1
7 2867
weaknessforcats
9,208 Expert Mod 8TB
Have you written down the steps to do this on paper?

A string is just an array of char with a \0 as the last element.

You could write a function with a string argument that compares two strings for equality.

Then you could write another function that has two string arguments that compares the first argument to the second argument by calling the compare function you just wrote. It starts with the first character of the first argument and if not equal repeats starting with the second character and so on. If a match is found, the function returns the location of the start of the match.

Now you know where the insert goes. So you write yet another function that takes the original string plus an argument for the string to insert plus an argument for the starting location. It copies the original string to a temp string up to the point of insertion, then copies the string to insert, then copies the rest of the original string.

I leave the memory management to you.
Oct 4 '08 #2
Expand|Select|Wrap|Line Numbers
  1. Code removed per Posting Guidelines
Important note: If you have two or more idetical words in the string and want to replace one of them, the far left one will automatically be replaced.
Oct 4 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
I'm sorry but is there a problem with this code? You don't say.
Oct 4 '08 #4
I'm sorry but is there a problem with this code? You don't say.
Please explain. Where did you find something wrong?
Oct 4 '08 #5
weaknessforcats
9,208 Expert Mod 8TB
I didn't say I found anything wrong. Usually when code is posted there is a probem with but you didn't say there was a problem with this code so I asked you what the problem was.

Are you saying this code is OK for you and you are just posting your finished product?
Oct 4 '08 #6
boxfish
469 Expert 256MB
I think curiously enough is providing abcmavdi with the code (s)he asked for. It seems to me that there is some sort of misunderstanding here.
Oct 4 '08 #7
I made a mistake in the code, the null charachter is used wrong, here is the code without the error:
Expand|Select|Wrap|Line Numbers
  1. Full code removed per Posting Guidelines
Oct 5 '08 #8

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

Similar topics

13
by: Nige | last post by:
To save me re-inventing the wheel, does anyone have a function to capitalise each word in form data? I was thinking along the lines of capitalise the first letter of the string, then any other...
0
by: windandwaves | last post by:
Hi folk Create two tables: 1. SOURCE 2. SOURCE_CONVERSION give them two fields: 1. ID = autonumber primary key
1
by: Elizabeth Harmon | last post by:
Hi All I am attempting to open a Word App from a web page and so far everything works (After reconfig of dcomcnfg for Microsoft Word Document). I have one minor problem, i cannot get the...
0
by: Balakrsihna | last post by:
Hi All, Can anyone tell me how to replace an image in MS Word 2003 using c#.net. I am converting an html file to word doc and sending this as attachment using System.Web.Mail; the...
1
by: James Vitale | last post by:
Using vb asp.net 1.1 I'm doing a word automation on a doc file and trying to do a find and replace. My existing code works fine except that it doesn't find and replace in the header. My code...
1
by: Michael Yanowitz | last post by:
Hello: I am hoping someone knows if there is an easier way to do this or someone already implemented something that does this, rather than reinventing the wheel: I have been using the...
4
by: hanseymoon | last post by:
Dear newsgroup: I've got this long function, which works good overall to spell check words from a dictionary and I am not in a position to replace it. Can someone please see where or how it...
14
by: Professor Yonce | last post by:
I have made form for E-Mail. I have entered code but the Import system does not work. It has squiggly line underneath it showing it is not communicating. It Will not build. Public Class...
8
by: Avi | last post by:
Hi all, I'm using string Replace(string oldValue, string newValue) and would like it to replace only full words that matches oldValue and not when oldValue is a substring of a larger word. ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.