user4741577
user4741577

Reputation:

Jquery: How to remove extra blank spaces that are present at the end of the string

I have a string

"Check Box  "

The string contain the extra spaces at the end. I want to remove those extra spaces as i am going to explode the middle spaces using '_'.

The problem is when i use explode function it also converts the end spaces to '_'

How to deal with that????

Upvotes: 2

Views: 461

Answers (3)

4b0
4b0

Reputation: 22323

Use trim before replace .

var str="Check Box  "
str = $.trim(str);
//Your replce logic goes 

Upvotes: 1

Sardoan
Sardoan

Reputation: 817

And with jquery: $.trim("Check Box ");

Upvotes: 3

user2226112
user2226112

Reputation:

No jQuery required for this:

"Check Box  ".trim()

Upvotes: 0

Related Questions