?
Solved

Remove a token from a string

Posted on 2005-03-03
2
Medium Priority
?
260 Views
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"
Token="/ZZ"
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,
-Jim

0
Comment
Question by:jim_welch_se
[X]
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
2 Comments
 
LVL 4

Accepted Solution

by:
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.

Steve
0
 
LVL 4

Expert Comment

by:sgvill
ID: 13451263
oh, you will also need to include

#include <string.h>
0

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