-4

I have a string like

var test = (-90.298205)

i want to remove ( ) character from this string using java script

Any thoughts? Thank you in advance for any help.

qooplmao
  • 17,622
  • 2
  • 44
  • 69
Krishna Ghodke
  • 589
  • 2
  • 6
  • 26

4 Answers4

3

You can use the string replace function with regular expression

var test = "(-90.298205)";
test = test.replace(/[()]/g, "");
Earth
  • 3,477
  • 6
  • 37
  • 78
3

If the parentheses are always the first and last character, then you don't need a regular expression:

test = test.substring(1, test.length - 1);

Although it looks like you don't have a string. The expression (-90.298205) is simply a (parenthesized) number. Why it's parenthesized is a mystery -- but you can't really "remove" the parentheses around it unless you remove those in the source itself. Even that won't change anything semantically (once parsed/interpreted, there's no difference between the parenthesized and non-parenthesized literal.)

1

You can Use .

var t = '(-90.298205)'; var output = t.replace(/[^\w\s\-\.]/gi, ''); alert(output);`
Maneesh Singh
  • 555
  • 2
  • 12
-1

use substring for example:



var str = "Hello world!";
var res = str.substring(0, 10);

The result of res will be:


Hello world

libisyne
  • 42
  • 2