douliang1891 2011-02-23 03:01
浏览 55
已采纳

是否有将美国位置字符串转换为单个部分的最佳做法?

Is there a best practice or common algorithm for implementing conversion of natural search string for locations location (US only) into its separate components?

for example:

City Name, ST 00000

TO

city => City Name
state => ST
zipcode => 00000

This is for a form so i dont need to handle any possible permutation - i can restrict the format to something like: city, st 00000 but i need to be able to handle omission of the any of the segments within the format, so that they optional to some extent... some examples of supported combinations (case insensitive):

00000 // zipcode
0000-00000 //zipcode
city, st / city and state - comma separated
city st // city and state - space separated
city, st 00000 // city state zip
st 00000 // state and zip - though i only really need the zip
city 00000 // city and zip - though i only really need the zip

I can also use a static set of State abbreviations so those could potentially be matched to validate a state segment if needed.

  • 写回答

2条回答 默认 最新

  • douxun4173 2011-02-23 09:14
    关注

    While i was researching I found some other code referenced in another SO question that i used while i was waiting... I modified the code here to support getting the zipcode as well as the city state: http://www.eotz.com/2008/07/parsing-location-string-php

    Others might also find this useful.

    @delphist: THANKS. Once i have time to compare accuracy and performance i may switch to your code if its better - its certainly simpler/shorter! If i do Ill mark it as the official answer.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?