[Last Call] Learn how to a build a cloud-first strategyRegister Now


How do I remove extra characters (spaces) at the end of a string?

Posted on 2007-10-02
Medium Priority
Last Modified: 2013-11-23
Pretty much as question implies.

I have a string which may have spaces at the end of it.  I want to check if it does and remove them if so.
Question by:Lamont77
1 Comment
LVL 16

Accepted Solution

imladris earned 500 total points
ID: 19999255
The trim function will remove any leading or trailing spaces from a String.

String mystring="This is a string     ";

String cleanstring=mystring.trim();

Now cleanstring will be "This is a string".

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month18 days, 13 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question