Remove a token from a string

Posted on 2005-03-03
Medium Priority
Last Modified: 2010-04-17
Hello Everyone,

I am wondering if anyone has a C or C++(non MFC) code that can find and remove a string from another string.

For example:

String= "A B C D /ZZ E F G H"
and the return would be
Returnstring="A B C D E F G H"

Any help you can provide would be greatly appreciated.

Best Regards,

Question by:jim_welch_se
  • 2

Accepted Solution

sgvill earned 150 total points
ID: 13451246
you can use strstr to find one string inside another.  For instance,

   char *pdest;
   int  result;
   pdest = strstr( string, str );
   result = pdest - string + 1;

Will return the index number in result of the original string where the token is.  You can use this to copy the original string up to that point, skip the token and then either check the remaining for another token or write the remaining string out as is if you are assured of only one token.


Expert Comment

ID: 13451263
oh, you will also need to include

#include <string.h>

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
No other job is as rewarding and demanding as building an iPhone app is. It is not really in the hands of the developer for the success of an iPhone app. Many factors operate jointly for every iOS application's success in the market.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question