Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

trim() - Clarification  RSS feed

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!