gpt4 book ai didi

java - 我正在从 USPS 获取串联地址行..我想以某种方式打破它

转载 作者:行者123 更新时间:2023-12-02 08:14:56 26 4
gpt4 key购买 nike

我们正在发送地址行 1 和地址行 2 进行验证。

当它进入 USPS 进行验证时,验证后它会连接 Address Line1 中的两个地址行。

例如:

AddressLine1: 20 ROOSEVELT AVE
AddressLine2: apt# 22

验证后,它将连接两个地址行:

AddressLine1: 20 Roosevelt Ave Apt# 209
AddressLine2: null

我想将返回的 Address Line1 作为经过验证的地址重新分成两行,我该如何执行此操作?

最佳答案

USPS 验证正在重新格式化文本,而不仅仅是连接两行。我不知道不同类型的地址可能涉及什么样的重新格式化,但在您的示例中,唯一的区别似乎是它已从大写更改为混合大小写,并且公寓号码已更改。我没有关于如何处理信息更改(例如数字更改)的建议,但如果只有大写/小写更改,您可以执行以下操作:

// you specified both Java AND JavaScript; I've picked JavaScript

var originalLine1 = "...",
originalLine2 = "...";

// somehow call USPS validation to set the following:
var validatedLine1 = "...",
validatedLine2 = "...",
validationPassed = true || false;

// now, did validation pass?
if (validationPassed) {
// if we can match the old line 1 with the left-hand side
// of the new line 1, and we're not going to be overwriting
// a non-null value in the new line 2 then split the new line 1
if (validatedLine2 === null &&
originalLine1.toLowerCase()
=== validatedLine1.substr(0,originalLine1.length).toLowerCase()) {

validatedLine2 = validatedLine1.substr(originalLine1.length);
validatedLine1 = validatedLine1.substr(0, originalLine1.length);
}
// do something with the results
}

话虽如此,调用USPS验证的目的是什么?如果它修改了文本,但通过了验证,也许您应该使用修改后的版本,因为大概遵循 USPS 的寻址标准?

关于java - 我正在从 USPS 获取串联地址行..我想以某种方式打破它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6619506/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com