How can I remove the parenthesis from this string in Javascript "(23,45)" ? I want it to be like this => "23,45" please!
Asked
Active
Viewed 2.1k times
0
-
Let Google be your friend - I couldn't type fast enough to get an answer after searching "javascript string replace" – Brian Barnes Oct 25 '13 at 07:28
6 Answers
18
Simply use replace with a regular expression :
str = str.replace(/[()]/g,'')
If you just wanted to remove the first and last characters, you could also have done
str = str.slice(1,-1);

Denys Séguret
- 372,613
- 87
- 782
- 758
-
Dude thanks! It worked perfectly with not even the slightest problem. – user2447830 Oct 26 '13 at 18:45
-
I was confused about the "-1" for a second. Looked it up - apparently if you use negative numbers with string.slice, the number will count from the end of the string instead of the start. – VSO May 05 '16 at 16:22
1
If they're always the first and last characters:
str = str.substr(1, str.length-2);

Barmar
- 741,623
- 53
- 500
- 612