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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:03:26+00:00 2026-06-12T05:03:26+00:00

Possible Duplicate: Query about the trim() method in Java I am parsing a site’s

  • 0

Possible Duplicate:
Query about the trim() method in Java

I am parsing a site’s usernames and other information, and each one has a bunch of spaces after it (but spaces in between the words).
For example: “Bob the Builder ” or “Sam the welder “. The numbers of spaces vary from name to name. I figured I’d just use .trim(), since I’ve used this before.
However, it’s giving me trouble. My code looks like this:

for (int i = 0; i < splitSource3.size(); i++) {
            splitSource3.set(i, splitSource3.get(i).trim());
}

The result is just the same; no spaces are removed at the end.
Thank you in advance for your excellent answers!

UPDATE:

The full code is a bit more complicated, since there are HTML tags that are parsed out first. It goes exactly like this:

for (String s : splitSource2) {
        if (s.length() > "<td class=\"dddefault\">".length() && s.substring(0, "<td class=\"dddefault\">".length()).equals("<td class=\"dddefault\">")) {
                splitSource3.add(s.substring("<td class=\"dddefault\">".length()));
        }
}

System.out.println("\n");
    for (int i = 0; i < splitSource3.size(); i++) {
            splitSource3.set(i, splitSource3.get(i).substring(0, splitSource3.get(i).length() - 5));
            splitSource3.set(i, splitSource3.get(i).trim());
            System.out.println(i + ": " + splitSource3.get(i));
    }
}

UPDATE:

Calm down. I never said the fault lay with Java, and I never said it was a bug or broken or anything. I simply said I was having trouble with it and posted my code for you to collaborate on and help solve my issue. Note the phrase “my issue” and not “java’s issue”. I have actually had the code printing out

System.out.println(i + ": " + splitSource3.get(i) + "*");

in a for each loop afterward.

This is how I knew I had a problem.
By the way, the problem has still not been fixed.

UPDATE:

Sample output (minus single quotes):

'0: Olin D. Kirkland                                          '
'1: Sophomore                                          '
'2: Someplace, Virginia  12345<br />VA SomeCity<br />'
'3: Undergraduate                                          '

EDIT the OP rephrased his question at Query about the trim() method in Java, where the issue was found to be Unicode whitespace characters which are not matched by String.trim().

  • 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-12T05:03:27+00:00Added an answer on June 12, 2026 at 5:03 am

    It just occurred to me that I used to have this sort of issue when I worked on a screen-scraping project. The key is that sometimes the downloaded HTML sources contain non-printable characters which are non-whitespace characters too. These are very difficult to copy-paste to a browser. I assume that this could happened to you.

    If my assumption is correct then you’ve got two choices:

    1. Use a binary reader and figure out what those characters are – and delete them with String.replace(); E.g.:

      private static void cutCharacters(String fromHtml) {
          String result = fromHtml;
          char[] problematicCharacters = {'\000', '\001', '\003'}; //this could be a private static final constant too
          for (char ch : problematicCharacters) {
              result = result.replace(ch, ""); //I know, it's dirty to modify an input parameter. But it will do as an example
          }
          return result;
      }
      
    2. If you find some sort of reoccurring pattern in the HTML to be parsed then you can use regexes and substrings to cut the unwanted parts. E.g.:

      private String getImportantParts(String fromHtml) {
          Pattern p = Pattern.compile("(\\w*\\s*)"); //this could be a private static final constant as well.
          Matcher m = p.matcher(fromHtml);
          StringBuilder buff = new StringBuilder();
          while (m.find()) {
              buff.append(m.group(1));
          }
          return buff.toString().trim();
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Parse query string into an array What's the fastest method , to
Possible Duplicate: TSQL query to concatenate and remove common prefix Hi How does one
Possible Duplicate: Query about Html <input type=password> tag…? I want change the character displayed
Possible Duplicate: Get query string values in JavaScript If one submits a GET form,
Possible Duplicate: php/Mysql query with inserting date fails I have a datepicker code below:
Possible Duplicate: Retrieve (or simulate) full query from PDO prepared statement I can't figure
Possible Duplicate: SQL Server Database query help Hi, I have a problem that I
Possible Duplicate: linq to sql recursive query I got stuck with having to build
Possible Duplicate: Writing an SQL query to SELECT item from the following table I
Possible Duplicate: jQuery won't parse my JSON from AJAX query So I have parsed

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.