String methods – trim() and length()

I this post, we will discuss about the string methods – trim() and length().

Let’s understand them one by one with examples.

trim():

The method trim() is used to remove leading and trailing white spaces from the input String.

e.g. Suppose, If we have a string ”   Name  “.  After using trim , String will remove the whitespaces i.e.  “Name”.

Output: After trimming the string – How are you???

length():

It is used to find out the no. of character in the string ,that is nothing but the length of the string.

Output: The length of the string is – 11
Ask Question
If you have any question, you can go to menu ‘Features -> Q&A forum-> Ask Question’.Select the desired category and post your question.
Print Friendly, PDF & Email
String method- indexof
String methods - substring
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...

1 Response

  1. August 6, 2015

    […] int length() […]

Leave a Reply

Your email address will not be published. Required fields are marked *