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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:56:10+00:00 2026-06-11T02:56:10+00:00

I asked a question earlier but met harsh criticism, so here I pose it

  • 0

I asked a question earlier but met harsh criticism, so here I pose it again. Simpler, and rephrased to appeal to those who may have been concerned about the way I asked it before.

BACKGROUND
I am parsing some HTML for information. I have isolated everything in a series of lines but the content I wish to grab and a bunch of spaces after it. To get rid of the spaces, I opted to use trim(), but I have been having trouble. The last few lines of my code are tests:

System.out.println("'" + someString + "'\n'" + someString.trim() + "'");

The results were:

'Sophomore                                          '
'Sophomore                                          '

I was worried I might have a problem with the way I was calling trim(), since we all make mistakes from time to time, so I tested it like this:

String s = "   hello         ";
System.out.println("'" + s+ "'\n'" + s.trim() + "'");

The results were:

'  hello     '
'hello'

MY QUESTION
What am I doing wrong? What I want is to get ‘Sophomore’, not ‘Sophomore                                          ‘

I look forward to your excellent answers (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-06-11T02:56:11+00:00Added an answer on June 11, 2026 at 2:56 am

    String.trim() specifically only removes characters before the first character whose code exceeds \u0020, and after the last such character.

    This is insufficient to remove all possible white space characters – Unicode defines several more (with code points above \u0020) that will not be matched by .trim().

    Perhaps your white space characters aren’t the ones you think they are?

    EDIT comments revealed that the extra characters were indeed “special” whitespace characters, specifically \u00a0 which is a Unicode “non-breaking space”. To replace those with normal spaces, use:

    str = str.replace('\u00a0', ' ');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked a similar question earlier but I'll ask it again in a different
I asked a similar question earlier but I'll ask it again in a different
I asked a question here earlier today and got that fixed, but now I
I asked this question earlier: How to get delta between two text items But
I asked this question earlier. I am intrigued by std::set but I have another
This question was asked earlier by someone else but never answered: MKAnnotation - Map
I asked another version of this question on the gamedev.SE site earlier today but
I have asked a question earlier but I think I missed the point so
I have already asked a similar question earlier but I have notcied that I
I asked this question earlier, but it got a negative vote, so I'm rewording

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.