admin管理员组文章数量:1432449
I have a string like (12.131883, -68.84942999999998)
and with using .replace()
I wish to remove the brackets, or get the values between the brackets. A simple latlon = latlon.replace('(',' '')
is not working.
Also tried it with latlon.replace(/\(.*?\)\s/g, '')
but no luck.
Can anyone help me out here?
I have a string like (12.131883, -68.84942999999998)
and with using .replace()
I wish to remove the brackets, or get the values between the brackets. A simple latlon = latlon.replace('(',' '')
is not working.
Also tried it with latlon.replace(/\(.*?\)\s/g, '')
but no luck.
Can anyone help me out here?
Share Improve this question asked Oct 9, 2015 at 20:07 Alvin BakkerAlvin Bakker 1,5361 gold badge21 silver badges41 bronze badges 5-
How is
"(12.131883, -68.84942999999998)".replace('(', '');
not working ? Any error ? I just tried it in the console and it works just fine.. – Nico Commented Oct 9, 2015 at 20:10 -
2
Use
substr
,var str = '(12.131883, -68.84942999999998)'; str.substr(1, str.length -2);
– Tushar Commented Oct 9, 2015 at 20:13 -
1
OR
str.replace(/\(|\)/g, '')
ORstr.replace(/[()]/g, '')
ORstr.match(/[^()]/g);
Choose whichever you like – Tushar Commented Oct 9, 2015 at 20:19 - Tushar, many thanx. Something this stupid I overlooked. – Alvin Bakker Commented Oct 9, 2015 at 20:27
- @AlvinBakker Glad to help :) – Tushar Commented Oct 9, 2015 at 20:31
2 Answers
Reset to default 4You can use substring
:
var myString = "(12.131883, -68.84942999999998)";
var latlong = myString.substring(1, myString.indexOf(')'));
Or:
var myString = "(12.131883, -68.84942999999998)";
var latlong = myString.substring(myString.indexOf('(') + 1, myString.indexOf(')'));
You can get them in an array with:
var latlon = "(12.131883, -68.84942999999998)";
var ll = latlon.match(/[-+]?[0-9]*\.?[0-9]+/g)
console.log(ll) // returns ["12.131883", "-68.84942999999998"]
本文标签: JavaScriptJQueryremoving brackets from stringStack Overflow
版权声明:本文标题:javascript - jQuery, removing brackets from string - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745036862a2638839.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论