This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes trim() - Clarification Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "trim() - Clarification" Watch "trim() - Clarification" New topic
Author

trim() - Clarification

Ram Adsumalli
Ranch Hand

Joined: Oct 16, 2006
Posts: 64
HI,

When i am going through online tutorial if came acrss the following statement

APP = resultSet.getString("NAME").trim();

NAME- It is the Cloumn name and it contains value the "Jeff Kiddy"

So the value will be like below

APP= Jeff Kiddy.

I am getting the same value when i used without trim(). Can any one help me what is use of the trim() and what it does.

Ram
David McCombs
Ranch Hand

Joined: Oct 17, 2006
Posts: 212
Learn to love the API docs

From the String class: "Returns a copy of the string, with leading and trailing whitespace omitted."

So in your example the String that is returned will contain the same string. trim() is used mainly to clean up user supplied input.
[ January 15, 2007: Message edited by: David McCombs ]

"Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration."- Stan Kelly-Bootle
Amit Rampurkar
Greenhorn

Joined: Sep 10, 2006
Posts: 14
Trim() is basically used to remove the trailing spaces. Suppose you are getting the value from a table and the value in the table is Jeff Kiddyxxx, where xxx refer to extra/trailing spaces stored in the table then calling trim() would return in "Jeff Kiddy".

Hope this helps
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: trim() - Clarification