• Post Reply Bookmark Topic Watch Topic
  • New Topic

Trim in StringBuilder and String  RSS feed

 
Greenhorn
Posts: 5
Chrome Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone. I'm new in this forum and the lenguage.

I have a question about an exercise of OraclePress.



The correct output is "I look good! and nice!" , but i don't understand for what .

Why the trim () method does not work? Whether is working on an object String.

Thanks a lot.
 
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is it that you are expecting trim() to do that it is not?
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
trim() removes white space not duplicates.
 
Emanuel Raúl
Greenhorn
Posts: 5
Chrome Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark King wrote:trim() removes white space not duplicates.


Sorry, but without understanding. Why not remove the blanks of the sentence?
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Emanuel Raúl wrote:
Sorry, but without understanding. Why not remove the blanks of the sentence?


Perhaps it would help us, if you told us what did you expect trim() to do? ... because clearly, you were expecting something else.

Henry
 
Emanuel Raúl
Greenhorn
Posts: 5
Chrome Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Emanuel Raúl wrote:
Sorry, but without understanding. Why not remove the blanks of the sentence?


Perhaps it would help us, if you told us what did you expect trim() to do? ... because clearly, you were expecting something else.

Henry


The function of the method trim () does not remove the spaces between words?
Why does not? Follow leaving spaces between words.
 
Mark King
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The trim() method removes all white space at the end of the string.
 
author & internet detective
Marshal
Posts: 37518
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's correct. trim() only removes whitespace at the beginning or end of a String. To remove spaces in the middle, you need to call replaceAll().
 
Sheriff
Posts: 4931
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Emanuel,

In a book they call it leading and trailing spaces, which has the same meaning as Jeanne Boyarsky mentioned: "whitespace at the beginning or end of a String".
 
Emanuel Raúl
Greenhorn
Posts: 5
Chrome Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh .. that stupid ... it's a silliness.

All for misreading.

Thanks you all.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!