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 126841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:22:54+00:00 2026-05-11T05:22:54+00:00

An extension to my previous question: Text cleaning and replacement: delete \n from a

  • 0

An extension to my previous question:
Text cleaning and replacement: delete \n from a text in Java

I am cleaning this incoming text, which comes from a database with irregular text. That means, there’ s no standard or rules. Some contain HTML characters like &reg, &trade, &lt, and others come in this form: &#8221, &#8211, etc. Other times I just get the HTML tags with < and >.

I am using String.replace to replace the characters by their meaning (this should be fine since I’m using UTF-8 right?), and replaceAll() to remove the HTML tags with a regular expression.

Other than one call to the replace() function for each replacement, and compiling the HTML tags regular expression, is there any recommendation to make this replacement efficient?

  • 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. 2026-05-11T05:22:55+00:00Added an answer on May 11, 2026 at 5:22 am

    My first suggestion is to measure the performance of the simplest way of doing it (which is probably multiple replace/replaceAll calls). Yes, it’s potentially inefficient. Quite often the simplest way of doing this is inefficient. You need to ask yourself: how much do you care?

    Do you have sample data and a threshold at which point the performance is acceptable? If you don’t, that’s the first port of call. Then test the naive implementation, and see whether it really is a problem. (Bear in mind that string replacement is almost certainly only part of what you’re doing. As you’re fetching the text from a database to start with, that may well end up being the bottleneck.)

    Once you’ve determined that the replacement really is the bottleneck, it’s worth performing some tests to see which bits of the replacement are causing the biggest problem – it sounds like you’re doing several different kinds of replacement. The more you can narrow it down, the better: you may find that the real bottleneck in the simplest code is caused by something which is easy to make efficient in a reasonably simple way, whereas trying to optimise everything would be a lot harder.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is an extension to a previous question I asked , today .... which
this question is an extension to a previous question i asked (and was answered).
(Note: This is an extension of a previous question .) I am having some
This is a question that is an extension of my previous Free 3 of
I develop an extension module for Guile, written in C. This extension module embeds
In a previous question on Stack Overflow , I had run into an issue
In a previous question, I asked whether ORM libraries were suboptimal solutions and received
Thanks to a previous question, I found out how to pull the most recent
I have some redirects in place from our previous site that used CakePHP. The
So I am having this problem wit my download link. Basically my previous way

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.