# How would you program this subroutine?

**URL:** <https://boards.straightdope.com/t/how-would-you-program-this-subroutine/494859>\
**Category:** In My Humble Opinion\
**Created:** [April 30, 2009, 4:45pm UTC](https://boards.straightdope.com/t/how-would-you-program-this-subroutine/494859 "2009-04-30T16:45:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tdn](https://avatars.discourse-cdn.com/v4/letter/t/94ad74/32.png) [@tdn](https://boards.straightdope.com/u/tdn)\
**Post date:** [April 30, 2009, 4:45pm UTC](https://boards.straightdope.com/t/how-would-you-program-this-subroutine/494859/1 "2009-04-30T16:45:50Z")

</div>

Let’s say I have strings in my VBScript code that look like this:

MR. JOSEPH SMITH  
123 FAKE STREET  
SPRINGFIELD OR 01234

I want it to look like this:

Mr. Joseph Smith  
123 Fake St.  
Springfield OR 01234

I could probably use the ucase and lcase functions to get it to look like that. Since each bit of demographic information is held in a discrete field, I can just lcase everything but the first character.

Now suppose I have strings like these:

MRS. GEORGIA O’KEEFE  
MR. RONALD MCDONALD  
MS. T’PRING K. VULCAN  
MR. DAVID ST. HUBBINS

How would you deal with that?

---

<div class="post-metadata">

**Author:** ![ZipperJJ](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/zipperjj/32/211_2.png) [@ZipperJJ](https://boards.straightdope.com/u/ZipperJJ)\
**Post date:** [April 30, 2009, 5:23pm UTC](https://boards.straightdope.com/t/how-would-you-program-this-subroutine/494859/2 "2009-04-30T17:23:50Z")

</div>

I would google my brains out trying to find someone else who has posted a function to do Proper Case that includes clauses for apostrophes and names starting with Mac, Mc and De. 😃

---

<div class="post-metadata">

**Author:** ![Voyager](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/voyager/32/133_2.png) [@Voyager](https://boards.straightdope.com/u/Voyager)\
**Post date:** [April 30, 2009, 6:22pm UTC](https://boards.straightdope.com/t/how-would-you-program-this-subroutine/494859/3 "2009-04-30T18:22:35Z")

</div>

Assuming you don’t get any results from **ZipperJJ** ’s excellent suggestion, I’d handle stuff like O’\<name\> and Mc\<name\> directly, and set up a hash for other possible exceptions. There is no way to distinguish the cases of MacDonald and Mackin, and De\<name\> is even worse. If you can find something like a downloadable telephone directory, you might be able to collect a lot of the names.

---

<div class="post-metadata">

**Author:** ![Ice\_Cream\_Conquest](https://avatars.discourse-cdn.com/v4/letter/i/e480ec/32.png) [@Ice\_Cream\_Conquest](https://boards.straightdope.com/u/Ice_Cream_Conquest)\
**Post date:** [April 30, 2009, 10:26pm UTC](https://boards.straightdope.com/t/how-would-you-program-this-subroutine/494859/4 "2009-04-30T22:26:48Z")

</div>

First of all 100% accuracy is impossible. There are certainly names out there that differ only by capitalization. Plus some people have weird names like “SanDee.” My question is then, “How much time are you willing to spend on accuracy?”

Guessing at figures, I think you’ll get better than 80% by using lcase on everything but the first letter. If you want to keep going, capitalize everything after punctuation (don’t forget hyphenated names) and then pick up Mac and Mc. I expect that will get you about 97% accuracy.

How would I solve it? I’d leave everything in upper case and go on to the next part of the project.

---

<div class="post-metadata">

**Author:** ![not\_alice](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/not_alice/32/7283_2.png) [@not\_alice](https://boards.straightdope.com/u/not_alice)\
**Post date:** [April 30, 2009, 10:33pm UTC](https://boards.straightdope.com/t/how-would-you-program-this-subroutine/494859/5 "2009-04-30T22:33:14Z")

</div>

I used to be on a mailing list that worked with such matters on a global scale, leading to some ISO standards IIRC regarding name and address formats.

The general case is not trivial - I hope you don’t have to turn in a homework assignment to solve it.

I seem to recall that the name of the list had the acronym grscdi, so maybe google can help (no guarantees on that acronym though it is probably close)

---

<div class="post-metadata">

**Author:** ![Athena](https://avatars.discourse-cdn.com/v4/letter/a/35a633/32.png) [@Athena](https://boards.straightdope.com/u/Athena)\
**Post date:** [May 1, 2009, 11:29am UTC](https://boards.straightdope.com/t/how-would-you-program-this-subroutine/494859/6 "2009-05-01T11:29:10Z")

</div>

As far as the cases for the names, I refuse to do it because it’s impossible to do with any sort of accuracy.

I can’t tell if you’re trying to standardize addresses or not. If you are, that is possible - I used to work at a company that did mailing list standardization & cleansing. You can write code that will go through a list of names & addresses and format them to the correct USPO standardized address format. However, as **not\_alice** says, this is not a trivial problem. This is the kind of problem people start businesses (BIG businesses) to fix. If you need address standardization, I suggest you contract with one of those businesses to do it for you; you can’t write the code yourself, at least not unless you have several programmers and several months.

---

<div class="post-metadata">

**Author:** ![tdn](https://avatars.discourse-cdn.com/v4/letter/t/94ad74/32.png) [@tdn](https://boards.straightdope.com/u/tdn)\
**Post date:** [May 1, 2009, 2:53pm UTC](https://boards.straightdope.com/t/how-would-you-program-this-subroutine/494859/7 "2009-05-01T14:53:55Z")

</div>

As for the scope of the project, I am the only programmer and I don’t have months to do this. But I’ll settle for 97% accuracy. I can’t predict what new names and addresses will come down the pike, but I do have a list of past names to work from already. If I can create cases for all of them, then there shouldn’t be a lot of surprises in the future.

The good news is that every letter created can be hand edited before it’s printed up and mailed out.

What concerns me most is names like “van der Linden M.D.” and “USMC.”

---

<div class="post-metadata">

**Author:** ![Driver8](https://avatars.discourse-cdn.com/v4/letter/d/b5a626/32.png) [@Driver8](https://boards.straightdope.com/u/Driver8)\
**Post date:** [May 1, 2009, 4:38pm UTC](https://boards.straightdope.com/t/how-would-you-program-this-subroutine/494859/8 "2009-05-01T16:38:02Z")

</div>

> [@tdn](#):
>
> As for the scope of the project, I am the only programmer and I don’t have months to do this. But I’ll settle for 97% accuracy. I can’t predict what new names and addresses will come down the pike, but I do have a list of past names to work from already. If I can create cases for all of them, then there shouldn’t be a lot of surprises in the future.
> 
> The good news is that every letter created can be hand edited before it’s printed up and mailed out.
> 
> What concerns me most is names like “van der Linden M.D.” and “USMC.”

Yes, you are right to be concerned! I like my small “v” in my “van Surname” style surname, and am annoyed at all the variations of my name that computers come up with (“Van Surname”, “Vansurname”, “Surname, Firstname Van”, etc). Why can’t you either leave it the way it was typed in or convert everything to a nice safe uppercase?

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [May 1, 2009, 5:42pm UTC](https://boards.straightdope.com/t/how-would-you-program-this-subroutine/494859/9 "2009-05-01T17:42:16Z")

</div>

> [@tdn](#):
>
> As for the scope of the project, I am the only programmer and I don’t have months to do this. But I’ll settle for 97% accuracy. I can’t predict what new names and addresses will come down the pike, but I do have a list of past names to work from already. If I can create cases for all of them, then there shouldn’t be a lot of surprises in the future.
> 
> The good news is that every letter created can be hand edited before it’s printed up and mailed out.
> 
> What concerns me most is names like “van der Linden M.D.” and “USMC.”

How bad is it to use first letter caps and fix the errors with special cases?
