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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Make the most of your online learning experience.
Simple Linear Regression
Six Sigma Control Plans
Suggested Courses

770 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