字符串变量中的进程地址 [英] Process Address in String Variable

查看:52
本文介绍了字符串变量中的进程地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在尝试在多行文本框中正确显示美国地址。

不幸的是,我必须处理的地址包含在字符串变量

中,格式为不统一。


例子:


John Smith,12345 Main Street,Anytown,NY 98776

John Smith ,12345 Main Street,Anytown,NY,98876

John Smith,c / o Jane Smith,12345 Main Street,Anytown,NY 98876

John Smith,c / o Jane史密斯,12345 Main Street,Anytown,NY,98876


你可能会注意到有些人在州之后有逗号,有些人不会。

另外在城市逗号之前有一个可变数量的逗号

和州。


问题是存储地址的原始程序放一个

逗号,地址中有换行符。不幸的是我

无法控制原始程序如何保存地址所以

我必须处理这个烂摊子。


我的问题是,我似乎无法隔离城市和

州之间的逗号。那个逗号显然需要保留,而其余部分需要用换行符代替



我有什么想法可以攻击它吗?


Hello I am trying to display a USA address properly in a multiline textbox.
Unfortunately the address I must process is contained in a string variable
and the format is not uniform.

Examples:

John Smith, 12345 Main Street, Anytown, NY 98776
John Smith, 12345 Main Street, Anytown, NY, 98876
John Smith, c/o Jane Smith, 12345 Main Street, Anytown, NY 98876
John Smith, c/o Jane Smith, 12345 Main Street, Anytown, NY, 98876

As you may notice some have a comma after the state and some don''t.
Also there are a variable number of commas before the comma between the city
and state.

The problem is that the original program that stores the address puts a
comma wherever there is a newline character in the address. Unfortunately I
have no control over how the addresses are saved by the original program so
I have to deal with this mess.

My problem is that I can''t seem to isolate the comma between the city and
state. That comma obviously needs to remain while the rest need to be
replaced with newline characters.

Any ideas how I might attack this?


推荐答案

哎呀我应该展示我正在寻找的结果。


John Smith

12345 Main Street

Anytown,NY 98776




John Smith

c / o Jane Smith

12345 Main Street

Anytown,NY 98776

-

Slonocode


我发烧了...唯一的处方是更多的牛铃

Oops I should probably show the result I''m looking for.

John Smith
12345 Main Street
Anytown, NY 98776
or

John Smith
c/o Jane Smith
12345 Main Street
Anytown, NY 98776
--
Slonocode

"I''ve got a fever...and the only prescripiton is more cowbell"


你好Sloncode,

我不是来自美国,所以我只看看它可能是豆子的问题

me。
Hi Sloncode,
I am not from the USA so I only look at the problem it could be beans to for
me.

John Smith,12345 Main Street,Anytown,NY 98776
John Smith,12345 Main Street,Anytown,NY,98876
John Smith,c / o Jane Smith,12345 Main Street,Anytown , NY 98876
John Smith,c / o Jane Smith,12345 Main Street,Anytown,NY,98876

John Smith, 12345 Main Street, Anytown, NY 98776
John Smith, 12345 Main Street, Anytown, NY, 98876
John Smith, c/o Jane Smith, 12345 Main Street, Anytown, NY 98876
John Smith, c/o Jane Smith, 12345 Main Street, Anytown, NY, 98876



当我看到它时,我认为每个地方都有3个逗号'' s是正确的。


然后我们有4个逗号类型和5个逗号类型的问题。


使用5个逗号我们可以替换带有"的最后一个逗号(我们知道这个地方

with lastindexof(",")

然后我们有一个地址,分裂后有一个长度为4的数组3

长度,比我认为的那么容易。


我没有把它放在代码中,因为我认为这不是问题,如果它这是消息吗?但是我认为这很容易做到。


Cor


When I see it, I think every adres with 3 comma''s is correct.

Then we have the problem of 4 comma types and the 5 comma types.

With the 5 commas we can replace the last comma with "" (we know the place
with lastindexof(",")

Then we have adresses which have after a split an array of 4 length and of 3
length, than it would be rather easy I think.

I did not put it in code because I think that is not the problem, if it is
message it, but I think this is quiet easy to do.

Cor


Cor写道:
你好Sloncode,
我不是来自美国所以我只看问题可能是豆子对我来说。
Hi Sloncode,
I am not from the USA so I only look at the problem it could be beans
to for me.

John Smith,12345 Main Street,Anytown,NY 98776
John Smith,12345 Main Street,Anytown,NY,98876
John Smith,c / o Jane Smith,12345 Main Street,Anytown ,纽约98876
John Smith,c / o Jane Smith,12345 Main Street,Anytown,NY,98876

John Smith, 12345 Main Street, Anytown, NY 98776
John Smith, 12345 Main Street, Anytown, NY, 98876
John Smith, c/o Jane Smith, 12345 Main Street, Anytown, NY 98876
John Smith, c/o Jane Smith, 12345 Main Street, Anytown, NY, 98876


当我看到它时,我认为每个带有3个逗号的地址是正确的。

然后我们有4个逗号类型的问题和5个逗号类型。

使用5个逗号我们可以用"替换最后一个逗号。 (我们知道
地方有lastindexof(,)

然后我们有一个地址,分裂后有4个长度的数组,长度为3个,比我觉得这很容易。

我没有把它放在代码中,因为我认为这不是问题,如果它是消息它,但我觉得这很容易安静做吧。

Cor


When I see it, I think every adres with 3 comma''s is correct.

Then we have the problem of 4 comma types and the 5 comma types.

With the 5 commas we can replace the last comma with "" (we know the
place with lastindexof(",")

Then we have adresses which have after a split an array of 4 length
and of 3 length, than it would be rather easy I think.

I did not put it in code because I think that is not the problem, if
it is message it, but I think this is quiet easy to do.

Cor




感谢回复Cor。


我本来应该放更多例如:


1. John Smith,12345 Main Street,Anytown,NY 98776

2. John Smith,12345 Main Street,Anytown,NY,98876

3. John Smith,c / o Jane Smith,12345 Main Street,Anytown,NY 98876

4. John Smith,c / o Jane Smith,12345 Main Street,Anytown ,纽约,98876

5. John Smith,12345 Main Street,Apt 8B,Anytown,NY 98876

6. John Smith,12345 Main Street,Apt 8B,Anytown, NY,98876

7. John Smith,c / o Jane Smith,12345 Main Street,Apt 8B,Anytown,NY 98876

8. John Smith,c / o Jane Smith,12345 Main Street,Apt 8B,Anytown,NY,

98876


我希望这个足够的例子表明我不能依赖于计算

逗号。


是的,只有3个逗号我可以轻松地处理它但是当有更多的时候,我似乎无法通过

计算它们来区分城市和州之间的逗号。


-

Slonocode


我发烧了......唯一的处方是更多的牛铃




Thanks for the reply Cor.

I should have put more examples:

1. John Smith, 12345 Main Street, Anytown, NY 98776
2. John Smith, 12345 Main Street, Anytown, NY, 98876
3. John Smith, c/o Jane Smith, 12345 Main Street, Anytown, NY 98876
4. John Smith, c/o Jane Smith, 12345 Main Street, Anytown, NY, 98876
5. John Smith, 12345 Main Street, Apt 8B, Anytown, NY 98876
6. John Smith, 12345 Main Street, Apt 8B, Anytown, NY, 98876
7. John Smith, c/o Jane Smith, 12345 Main Street, Apt 8B, Anytown, NY 98876
8. John Smith, c/o Jane Smith, 12345 Main Street, Apt 8B, Anytown, NY,
98876

I hope this is enough examples to show that I can''t rely on counting the
commas.

Yes when there are only 3 commas I can proccess it easily but when there are
more I can''t seem to isolate the comma between the city and state just by
counting them.

--
Slonocode

"I''ve got a fever...and the only prescripiton is more cowbell"



这篇关于字符串变量中的进程地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆