473,598 Members | 3,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Process Address in String Variable

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?


Nov 20 '05 #1
12 1558
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"

Nov 20 '05 #2
Cor
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

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
Nov 20 '05 #3
Cor wrote:
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

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


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"


Nov 20 '05 #4
* "Slonocode" <st***********@ yahoo.com> scripsit:
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


I think it's not easy to get the right result because I am nut sure if
there will be a unique representation. How whould the application know
if it should read

...
Anytown, NY
98876

or

...
Anytown
NY, 98876

Converting the data automatically may cause invalid results. Do you
know if the application that writes the file is able to restore all the
data correctly?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #5
Hi Slonocode,

Working from the right hand side seems to be useful:

Every address ends with a space and a zip code.
Whip it off with LastIndexOf (" ").
Then Trim the end.
The it it EndsWith (",") remove that.
Then every address ends with a state code.
Whip it off. and add it to the zip code.

All other commas become new lines.

Regards,
Fergus
Nov 20 '05 #6
Herfried K. Wagner [MVP] wrote:
I think it's not easy to get the right result because I am nut sure if
there will be a unique representation. How whould the application
know if it should read

...
Anytown, NY
98876

or

...
Anytown
NY, 98876

Converting the data automatically may cause invalid results. Do you
know if the application that writes the file is able to restore all
the data correctly?


Yes the original application will restore the data correctly. The original
application stores its info in a MS Access database(If that matters). The
original application allows me to export the data to a text file which is
what I have to read from. The Database is locked so I can't read from it
directly.

The original application seems to put a comma whereever there was a newline
character. Right now I'm baffled as to how it restores the correct
formatting unless having the data in a MS Access DB is easier.

--
Slonocode

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


Nov 20 '05 #7
Cor
Hi Slonocode
Another approach I saw your second message when I had almost finesed the
solution
What my start for that approach is, that in your example the first 3 rows
are always between the 3 first commas or the end. (What it is does not
matter). And then comes the problems.
But therefore I need to see how that last adress is written.
(I think that that extra "apt8b" is in almost every adres system is the
problem, but maybe with you not)
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, 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


Nov 20 '05 #8
hope you can make sence of this :/

pseudo here i think it could work (if someone would be so kind to check it
:)

declare strings for al the possible fields (you can do w the w you want
later)
and declare a commacount and a backcommacount as int

strName = split text till first comma
if split text from first comma starts w c/o then
strCO = split text from first til second comma
strstreet = split text from 2nd til 3d comma
commacount = 3
else
strstreet = split text from first till second comma
commacount = 2
end if

if the apt field always starts w apt you can go on like that else start from
the back now
temptext = split text from last comma till end
if temptext = nummeric
strpostcode = temptext
strState = split text from 2nd last comma till last comma
backcommacount = 2
else
strState = split temptext on space (1nd part)
strpostcode = split temptext on space (2nd part)
backcommacount = 1
end if

strTown = split text from backcommacount -1 comma till backcommacount comma
backcommacount +=1

if split text from backcommacount - 1 till backcommacount <> strstreet then
strApp = split text from backcommacount - 1 till backcommacount
end if
Nov 20 '05 #9
Fergus Cooney wrote:
Hi Slonocode,

Working from the right hand side seems to be useful:

Every address ends with a space and a zip code.
Whip it off with LastIndexOf (" ").
Then Trim the end.
The it it EndsWith (",") remove that.
Then every address ends with a state code.
Whip it off. and add it to the zip code.

All other commas become new lines.

Regards,
Fergus


Thanks Furgus

All I can say is "DOH" why didn't I think of that.
--
Slonocode

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

Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
4870
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE) p.stdin.write("hostname\n") however, it doesn't seem to work. I think the cmd.exe is catching it.
5
4301
by: Shuaib | last post by:
I wonder if anybody could shed some light on a problem I am encountering. I have written a program in C that runs on Solaris 2.8. At busy times of the day there may be multiple instances of it running (5-10), each process taking approx. 3 seconds to complete. Each instance of the program basically fetches data from a Oracle database (using Remedy ARS API routines) and stores it in a user defined structure that I have defined as a...
12
2360
by: Raymond Lewallen | last post by:
How to wait for a process to stop completion is my goal. Obviously, the looping while waiting for the HasExited property is not a solution.. but thats the best I can come up off the top of my head. Natuarally it will not work. I expect it to use up all resources looping, which will not allow the process to complete. The process takes about 60 seconds, because the .bat file it is calling is rebuilding mulitple .NET solutions and projects...
7
2571
by: MgGuigg | last post by:
Hello all, This is my first time posting a question to this forum, so here is hoping I am following protocol. I am scraping the rust off my old Basic programming skills, and have just recently upgraded to VB.NET, and I have a lot of catching up to do. That being said, I have come a long way in a short while, however, I am stumped at the moment. I have read through days of posts, but have not been able to address my specific question, so...
19
3093
by: Manish Tomar | last post by:
Hi All, The following code as per my knowledge should not work: int* some() { int b = 10; return &b; }
3
4281
by: BuddyWork | last post by:
Hello, Could someone please explain why the Socket.Send is slow to send to the same process it sending from. Eg. Process1 calls Socket.Send which sends to the same IP address and port, the receiver is running within Process1. If I move the receiver into Process2 then its fast. Please can someone explain.
0
3153
by: Buddy Home | last post by:
There is two examples of code. Example 1. Send and Receive within the same process. Put this code in a console app called SendAndReceive and run the code. using System; using System.Collections.Generic; using System.Net; using System.Net.Sockets; using System.Runtime.Serialization.Formatters.Binary;
14
16159
by: Spitfire | last post by:
Hi All, I've this weird question about pointers. I would like to know how to return the address of a local variable, safely!! Isn't that a unrecommended procedure? Doesn't it have possibilities that the variable could be deallocated from memory and the dereferencing of the returned pointer somewhere else could crash the program? If it's not safer to do such an operation, how do functions like strtok for example work??? --
0
2547
by: ravindrag | last post by:
Hi, I am getting error SQL1131N during sqlj.install_jar(...). There is no useful message in the diag.log (even with diag level 4). I am giving the diag.log entries at the end of this posting (would have been ideal if there was an option to attach the file). command: db2 call sqlj.install_jar('file:/home/xyz/abc.jar','def.abc') response: SQL1131N DARI (Stored Procedure) process has been terminated abnormally. SQLSTATE=38503
0
7991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8395
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8398
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6719
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5850
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5438
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3898
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3939
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1504
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.