How to replace pound (currency) sign with javascript?

I am trying to remove the pound sign (£) from a string using javascript. I am trying to do this using

str = str.replace(/\£/g, "");

However, he does not delete the sign.

The str value is retrieved from the range (and the correct value is selected). This range was previously set using javascript, and it was encoded in a string as

£

Any ideas on the best way to remove the pound sign?

+5
source share
6 answers

You may need to use unicode for this. For instance,'£10.00'.replace(/\u00A3/g, '');

+9
source

Remove backslash from your regular expression.

+3
source

, :

var str = "£sdfsdf";

str = str.replace("£", "");

alert(str);

: http://jsfiddle.net/peUrn/1/

+3

"hello w£orld".replace(/£/g,"")
+1

:

str.replace('£', '');
+1

Encodes the Uniform Resource Identifier (URI) component, replacing each instance of certain characters with one, two, or three escape sequences representing UTF-8 character encoding

This means that JavaScript uses 2 characters to encode the pound sign.

£ = %C2%A3

See http://fyneworks.blogspot.com/2008/06/british-pound-sign-encoding-revisited.html for more details .

It is best to use% C2% A3 instead of the pound sign in your script.

0
source

All Articles