Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7624173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:53:37+00:00 2026-05-31T04:53:37+00:00

I have been having a bit of trouble with my find and replace function

  • 0

I have been having a bit of trouble with my find and replace function I can get it to replace all characters but I only want it to change the characters that match the banned words.

Here is my code so far

class getTextData
{   
private:
    string currentWord;
    vector<string> bannedWords;
    vector<string> textWords;
    int bannedWordCount;
    int numWords;
    char ch;
    int index[3];
    ifstream inFile ();
public:
    void GetBannedList(string fileName);
    void GetWordAmount(string fileName);
    void GetDocumentWords(string fileName);
    void FindBannedWords();
    void ReplaceWords(string fileOutput);
};

for(int i = 0; i <= numWords; i++)
{
    for(int j = 0; j < bannedWordCount; j++)
    {
        if(string::npos != textWords[i].find(bannedWords[j]))
        {               
            textWords[i] = "***";
        }
    }
}

This just replaces with a fixed number of * but I want it to replace the characters it finds with a * not the whole word.

Thanks In Advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:53:39+00:00Added an answer on May 31, 2026 at 4:53 am

    Try this:

    for(int i = 0; i <= numWords; i++)
    {
        for(int j = 0; j < bannedWordCount; j++)
        {
            size_t pos = textWords[i].find(bannedWords[j]
            if(string::npos != pos))
            {               
                textWords[i].replace(pos, bannedWords[j].length(), 
                                     bannedWords[j].length(), '*');
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having a lot of trouble figuring out how I can access
I have been having quite a bit of trouble implementing unit testing on the
I have been doing a bit of research on this but, I am having
i have a bit of stupid question, but i'm really having trouble with it.
I have been having a bit of trouble with this issue with a while
I have been having some problems trying to get my PHP running. When I
Hello I have been having trouble with this for a while now. I have
I am having a bit of trouble working out when an image has been
I'm having a bit of trouble with knowing how I can save items from
I know that similar questions have been asked all over the place, but I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.