0

Here's my function call:

removeTags(*buf, bufSize);

which calls:

void removeTags(char* dataBlock, unsigned long size) 
{
    char* start = dataBlock; 
    char* end = dataBlock + size;

    while(start < end)
    {
    //How do I replace the characters "\abc" with just nothing, ''.
        }

I want to replace any instances of the characters \abc with nothing.

0

2 Answers 2

2

Once you find an instance of \abc simply move all the characters after the \abc backwards four places (four because \abc is four chars long) (possibly using memmove).

For instance:

one two \abc three
        <----^ copy everything from the 't' down backwards over the \abc

Note that after you do that, your end pointer will be invalidated so you'll have to update it.

Finding the position of a string within another string can be done with strstr for const char*s or std::string::find for std::strings. Of course, if you're using std::string, then you could just use std::string::replace.

Sign up to request clarification or add additional context in comments.

1 Comment

Any downside to setting pointer's memory content = to a string and just doing the string replacing: string xyz = *buf; The buf pointer is output to a file in the next line anyway. This app converts an old ebook format to an RTF file. I don't understand pointers well enough to do this search and replace. Seems to work fine converted to a string.
0

You remove the unwanted characters by moving all the following characters down.

You should be able to do it in a single pass by having a from_pointer and a to_pointer and either copy the current at from_pointer to to_pointer or increment from_pointer to skip over the characters you're omitting.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.