Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to remove the last empty keys in a string

I have a string that looks like this:

"a               "

As you can see there is only one character that is not empty " ". How do I remove the last charaters of the string so only the valid one(s) will remain:

"a"

This can also be considered in cases where the first characters are empty:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

"         a"

I cannot simply remove each empty key as they can be part of a more complex sentence like this:

"I love Js            "

>Solution :

In order to be able to remove easily the trailing spaces
I suggest that you use the trim() method.

a '.trim() // return 'a'

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading