Striping apostrophe from beginning and end of string using JavaScript

For me the JavaScript only provides most primitive set of capabilities that are required by most developers. That is one reason what made jQuery a popular framework. 

To do even simple thing like trimming a sting with a know character is not possible unless you write your own routine. What I have demonstrated here is addition of a function to String type to remove single quotes (an apostrophe) from beginning and end of a string.

String.prototype.unquoted = function (){return this.replace (/(^’)|(‘$)/g, ”)}

var str=”‘hello'”

alert(str.unquoted());

http://jsfiddle.net/oj8jk95s/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s