Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

.trim

  Asked By: Dylan    Date: Aug 20    Category: Java    Views: 477
  

I am looking at some code where this is defined:
String str;
System.out.println("Mensaje :"+ str.trim());
but dont know what this means:
str.trim

Share: 

 

6 Answers Found

 
Answer #1    Answered By: Verner Fischer     Answered On: Aug 20

Trim removes any following whitespace from your string

"asdfadsf " would trim to "asdfadsf"

 
Answer #2    Answered By: Luz Hayes     Answered On: Aug 20

trim() function in String class is used to remove both leading and trailing
(white)spaces of a String.

for example:-

String str = " Hello World ");
System.out.println(str.trim());

will print only "Hello World" in ur console.
note: it will not remove blank spaces in-between the String

 
Answer #3    Answered By: Vidos Fischer     Answered On: Aug 20

String <java.sun.com/.../String.html>

trim <java.sun.com/.../String.html#trim()> ()
Returns a copy of the string, with leading and trailing whitespace
omitted.





Example:



String str = "a e i o u";



System.out.println(str);

str = str.trim();

System.out.println(str);



Your outputs will be:



a e i o u

aeiou

 
Answer #4    Answered By: Hoor Khan     Answered On: Aug 20

java.sun.com/.../String.html#trim()

If question is about, what trim( ) does, trim( ) returns a copy of the
string, with leading and trailing whitespace omitted.

Please note trim( ) removes leading and trailing spaces only, not spaces
which are in mid of some letters.

For eg:

str = " s t r ";

str.trim() retruns "s t r" means  it does not removes spaces in between
any letters.

 
Answer #5    Answered By: Hugo Williams     Answered On: Aug 20

Yes... You're right...

And I was wrong. I miss interpreted....

 
Answer #6    Answered By: Amelia Schmidt     Answered On: Aug 20

trims whitespaces....................

 
Didn't find what you were looking for? Find more on .trim Or get search suggestion and latest updates.




Tagged: