我有一个包含以下条目的.CSV文件。最后一个条目是位置
我希望不用手动提取纬度和经度。任何人都可以建议一种方法吗?请帮忙。
前两个条目是:
"Type","LicenseNumber","Name","Building","StreetName","Location","City","State","Zip","Tel","Loc"
"ELECTRONICS STORE",800057,"CAMERA LAND INC",575,"LEXINGTON AVENUE",,"NEW YORK","NY",10022,2127535128,"LEXINGTON AVENUE
NEW YORK, NY 10022
(40.7588057463651, -73.9680023077056)"
答案 0 :(得分:1)
您可以将任何编程语言与正则表达式一起使用。 Perl示例如下。
将以下内容保存到脚本
#!/usr/bin/perl -w
use strict;
while ( my $line = <> ) {
#match paretheses, followed by a number, followed by comma, followed by optional space, followed by number, followed by paretheses, followed by end of line
if ( $line =~ /\((-?\d+\.\d+), ?(-?\d+\.\d+)\)"$/ ) {
print "Latitude: $1, Longitude: $2\n";
}
else {
print "expression not found in line $.\n";
}
}
并在CSV文件上运行。
$ perl my_script.pl my_file.csv
答案 1 :(得分:1)
这是您想要使用的Java库 http://sourceforge.net/projects/libcsv/ 和另一个图书馆http://opencsv.sourceforge.net/ 最后使用split(“\,”) http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#split(java.lang.String) 得到你的经度,纬度。
希望有所帮助