I have this string:
var str = ? this is a ? test ?;
Now I want to get this:
var newstr = this is a ? test;
As you see I want to remove just those ?
surrounding (in the beginning and end) that string (not in the middle of string). How can do that using JavaScript?
Here is what I have tried:
var str = ? this is a ? test ?;
var result = str.trim(?);
document.write(result);
So, as you see it doesn't work. Actually I'm a PHP developer and trim()
works well in PHP. Now I want to know if I can use trim()
to do that in JS.
It should be noted I can do that using regex, but to be honest I hate regex for this kind of jobs. Anyway is there any better solution?
Edit: As this mentioned in the comment, I need to remove both ?
and whitespaces which are around the string.