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

  • SEARCH
  • Home
  • 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 8343811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:10:37+00:00 2026-06-09T06:10:37+00:00

I want to know (with examples!) if there is a way to search through

  • 0

I want to know (with examples!) if there is a way to search through a list (not a file) and if it’s found replace it.

Background: Making a server but I want it to censor swear words and the system i have works it’s just not efficient enough.

Current Code:

     String impmessage = message.replaceAll("swearword1", "f***");
     String impmessage2 = impmessage.replaceAll("swearword2", "bi***");
     String impmessage3 = impmessage2.replaceAll("swearword3", "b***");
     String impmessage4 = impmessage3.replaceAll("swearword4", "w***");
     ...
     String impmessage8 = impmessage7.replace('%', '&');

The whole shabang. But when I want to add a new word into the filter I have to add another one on there.

  • 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-06-09T06:10:39+00:00Added an answer on June 9, 2026 at 6:10 am

    Your basic solution is below:

    Map<String, String> mapping = new HashMap();
    mapping.put("frak","f***");
    
    String censoredMsg = message;
    for (String word : mapping.KeySet()) {
      censoredMsg = censoredMsg.replaceAll(word, mapping.get(word));
    }
    

    How you create the mapping is somewhat up to you. Here is another more comprehensive solution including pulling in from a random file:

    public class TheMan {
      private Set<String> uglyWords;
    
      public TheMan() {
        getBlacklist();
      }
    
      private void getBlacklist() {
        Scanner scanner = new Scanner(new File("wordsidontlike.txt"));
        while (scanner.hasNext()) {
          String word = scanner.nextLine();
          uglyWords.add(word);
        }
      }
    
      public String censorMessage(String message) {
        String censoredMsg = message;
        for (String word : uglyWords) {
          String replacement = word.charAt(0);
          StringUtils.rightPad(replacement, word.length(), '*');
          censoredMsg = censoredMsg.replaceAll(word, replacement);
        }
        return censoredMsg;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to know if there's any way to update from all versions (Example:
I know there are thousands of examples on the internet, but I want for
I just want to know whether there is a way to answer this question
I have found a XML file through google search that will help me for
For example: I want to know if there are images in a directory (eg.
On clicking child, I want to know the parent index no. Example, there is
Sorry in advance if I'm not explaining this correctly. I want to know if
Is there a way to search specific information on the internet or on a
I want to know how to set up a way to contact others without
Is there any way how to call JQuery function from PageLoad C# file? Basically

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.