簡體   English   中英

Javascript-從括號內獲取字符串的內容

[英]Javascript - Get the content of a string from inside a parenthesis

我有一個從ajax請求中獲取的字符串。 字符串格式如下:

  POINT(417135.05230943 4187636.37572952)

我想要的是獲取括號中的內容,以使用它來做一個標記(緯度,經度)。

現在,我這樣做:

response = response.replace("POINT(",'');
response = response.replace(")",'');
response = response.replace(" ",',');
//alert(response);
var latlotArr = response.split(',');

我一點都不喜歡。 還有另一種方法嗎? 我想不可能將其轉換為JSon。 我有什么選擇?

一堆的方法來做到這一點。

一種方法是使用基本正則表達式來匹配由空格分隔的兩組數字。

var str = "POINT(417135.05230943 4187636.37572952)";
var points = str.match(/(\d+.\d+)\s(\d+.\d+)/);
console.log(points[1], points[2]);

如果需要,您可以根據自己的需要獲得更多具體信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM