Help needed: Producing a mixed case surname....DONE! 
Author Message
 Help needed: Producing a mixed case surname....DONE!



Quote:
> And one more case that can produce damage - not only are there no genreal

rules for capitalization of names like this, but there are
Quote:
> also cases where people choose two different captializations of otherwise

identically spelled names-
Quote:

> e.g.,
> DeLaCroix,Delacroix
> Mckay, McKay

> If you want to flag "high danger" names for potential miscapitalization,

though, here are 2 rules that I might suggest - again, this
Quote:
> is just an idea for review since there is no useful rule in English.

Furthermore, I am only roughly hitting names from Northwestern
Quote:
> Europe in the  following "pattern"...

> (1) Names with either of the punctuation marks ' or - in them.  The ' will

catch Many Irish last names and flaggin the - will
Quote:
> capture hyphenated names.

> (2) To capture some potential names of common Western European heritage

and might be miscapitalized, flag names which begin with one
Quote:
> of the following:
> di,da,de,do,du,la,le,lo,mc,mac,van,von

> Short story is, though - there is no simple method to cover for this human

error, since there is no computational rule to follow.
Quote:





Quote:
> > > I would like to build a JScript function that returns a mixed case
surname
> > > from a surname passed into it in any case.

> > > e.g. Pass in MACDONALD - return MacDonald
> > > MCARTHUR - McArthur
> > > O'DONNELL - O'Donnell
> > > digiacomo - DiGiacomo

> > > Is there any functions already out there? Or is there a simple way to
build
> > > one myself?

> > > Any suggestions at all would be very welcome.

> > > TIA,

> > > John

> > This will wind up being more trouble than it's worth. Certain of your
> > cases, such as those with apostrophes or names beginning with "Mc",
> > could be handled, but other cases will be problematic. What about the
> > last name "Mackey"? Or "Dickens"?

I have produced my function (it *had* to be done). I have not seen it trip
up once. There are some names that would fail. DIGIACOMO would produce
Digiacomo and not DiGiacomo; but DI GIACOMO would correctly produce Di
Giacomo. Almost all other names are fine. Please note: the names I use are
common surnames in the U.K., so it might not be so easy in other countries.

Here's how I did it:

function make_MailingName(InTitle, InInitial, InSurname) // This function
builds a mixed case 'Mailing Name', whatever the format of the surname
{
 var ModSurname = InSurname.toLowerCase();

 firstTwo = ModSurname.substring(0,2);
 firstTwoRest = ModSurname.substr(2);
 firstThree = ModSurname.substring(0,3);
 firstThreeRest = ModSurname.substr(3);

 if (ModSurname == "macauley" || ModSurname == "mackie" || ModSurname ==
"machie" || ModSurname == "macken" || ModSurname == "mackey" || ModSurname
== "macari" || ModSurname == "machon")
 {
  Except1 = ModSurname.substring(0,1); //first letter lower-case
  UExcept1 = Except1.toUpperCase(); // first letter now capitalised
  Except2 = ModSurname.substr(1); // rest of name

  OutSurname = UExcept1 + Except2;
 }

 else if (firstThree == "mac") // format names with 'Mac' at start
 {
  if (ModSurname.length < 6)
  {
   MacShort1 = ModSurname.substring(0,1); //first letter lower-case
   UMacShort1 = MacShort1.toUpperCase(); // first letter now capitalised
   MacShort2 = ModSurname.substr(1); // rest of name

   OutSurname = UMacShort1 + MacShort2;
  }

  else
  {
   OutSurname = UOther1 + Other2;
   Mac1 = firstThree.substring(0,1); //'m' at start
   UMac1 = Mac1.toUpperCase(); // now 'M'
   Mac2 = firstThree.substr(1); // 'ac'
   Macx1 = firstThreeRest.substring(0,1); // 'd'
   UMacx1 = Macx1.toUpperCase(); //'D'
   Macx2 = firstThreeRest.substr(1); //'onald'

   OutSurname = UMac1 + Mac2 + UMacx1 + Macx2;
  }
 }

 else if (firstTwo == "mc") // format names with 'Mc' at start
 {
  Mc1 = firstTwo.substring(0,1); //'m' at start
  UMc1 = Mc1.toUpperCase(); // now 'M'
  Mc2 = firstTwo.substr(1); // 'c'
  Mcx1 = firstTwoRest.substring(0,1); // 'g'
  UMcx1 = Mcx1.toUpperCase(); //'G'
  Mcx2 = firstTwoRest.substr(1); //'uire'

  OutSurname = UMc1 + Mc2 + UMcx1 + Mcx2;
 }

 else if (firstTwo == "o'") // format names with O' at start
 {
  O1 = firstTwo.substring(0,1); //'o' at start
  UO1 = O1.toUpperCase(); // now 'o'
  O2 = firstTwo.substr(1); // '''
  Ox1 = firstTwoRest.substring(0,1); // 'd'
  UOx1 = Ox1.toUpperCase(); //'D'
  Ox2 = firstTwoRest.substr(1); //'onnell'

  OutSurname = UO1 + O2 + UOx1 + Ox2;
 }

 else if (ModSurname.search("-") > -1) //search for double-barrelled name
with hyphen
 {
  HyphenIndex = ModSurname.indexOf("-");
  HPartOne = ModSurname.substring(0,HyphenIndex); //first part of dbl
barrelled name
  HPartTwo = ModSurname.substr(HyphenIndex + 1); //second part of dbl
barrelled name

  HPartOne1 = HPartOne.substring(0,1); //first letter lower-case
  UHPartOne1 = HPartOne1.toUpperCase(); // first letter now capitalised
  HPartOne2 = HPartOne.substr(1); // rest of name

  HPartTwo1 = HPartTwo.substring(0,1); //first letter lower-case
  UHPartTwo1 = HPartTwo1.toUpperCase(); // first letter now capitalised
  HPartTwo2 = HPartTwo.substr(1); // rest of name

  OutSurname = UHPartOne1 + HPartOne2 + "-" + UHPartTwo1 + HPartTwo2;
 }

 else if (ModSurname.search(" ") > -1) //search for double-barrelled name
with space
 {
  SpaceIndex = ModSurname.indexOf(" ");
  SPartOne = ModSurname.substring(0,SpaceIndex + 1); //first part of dbl
barrelled name
  SPartTwo = ModSurname.substr(SpaceIndex + 1); //second part of dbl
barrelled name

  SPartOne1 = SPartOne.substring(0,1); //first letter lower-case
  USPartOne1 = SPartOne1.toUpperCase(); // first letter now capitalised
  SPartOne2 = SPartOne.substr(1); // rest of name

  SPartTwo1 = SPartTwo.substring(0,1); //first letter lower-case
  USPartTwo1 = SPartTwo1.toUpperCase(); // first letter now capitalised
  SPartTwo2 = SPartTwo.substr(1); // rest of name

  OutSurname = USPartOne1 + SPartOne2 + " " + USPartTwo1 + SPartTwo2;
 }

 else
 {
  Other1 = ModSurname.substring(0,1); //first letter lower-case
  UOther1 = Other1.toUpperCase(); // first letter now capitalised
  Other2 = ModSurname.substr(1); // rest of name

  OutSurname = UOther1 + Other2;
 }

 return(InTitle + " " + InInitial + " " + OutSurname);

- Show quoted text -

Quote:
}



Sun, 27 Jun 2004 17:15:15 GMT  
 Help needed: Producing a mixed case surname....DONE!
"I don't care what you say, Orville and Wilbur will never get it off the ground..."

That's pretty nifty.  The fact that you're not doing it in North America makes it a lot easier, too ;).

Quote:



> > And one more case that can produce damage - not only are there no genreal
> rules for capitalization of names like this, but there are
> > also cases where people choose two different captializations of otherwise
> identically spelled names-

> > e.g.,
> > DeLaCroix,Delacroix
> > Mckay, McKay

> > If you want to flag "high danger" names for potential miscapitalization,
> though, here are 2 rules that I might suggest - again, this
> > is just an idea for review since there is no useful rule in English.
> Furthermore, I am only roughly hitting names from Northwestern
> > Europe in the  following "pattern"...

> > (1) Names with either of the punctuation marks ' or - in them.  The ' will
> catch Many Irish last names and flaggin the - will
> > capture hyphenated names.

> > (2) To capture some potential names of common Western European heritage
> and might be miscapitalized, flag names which begin with one
> > of the following:
> > di,da,de,do,du,la,le,lo,mc,mac,van,von

> > Short story is, though - there is no simple method to cover for this human
> error, since there is no computational rule to follow.





> > > > I would like to build a JScript function that returns a mixed case
> surname
> > > > from a surname passed into it in any case.

> > > > e.g. Pass in MACDONALD - return MacDonald
> > > > MCARTHUR - McArthur
> > > > O'DONNELL - O'Donnell
> > > > digiacomo - DiGiacomo

> > > > Is there any functions already out there? Or is there a simple way to
> build
> > > > one myself?

> > > > Any suggestions at all would be very welcome.

> > > > TIA,

> > > > John

> > > This will wind up being more trouble than it's worth. Certain of your
> > > cases, such as those with apostrophes or names beginning with "Mc",
> > > could be handled, but other cases will be problematic. What about the
> > > last name "Mackey"? Or "Dickens"?

> I have produced my function (it *had* to be done). I have not seen it trip
> up once. There are some names that would fail. DIGIACOMO would produce
> Digiacomo and not DiGiacomo; but DI GIACOMO would correctly produce Di
> Giacomo. Almost all other names are fine. Please note: the names I use are
> common surnames in the U.K., so it might not be so easy in other countries.

> Here's how I did it:

> function make_MailingName(InTitle, InInitial, InSurname) // This function
> builds a mixed case 'Mailing Name', whatever the format of the surname
> {
>  var ModSurname = InSurname.toLowerCase();

>  firstTwo = ModSurname.substring(0,2);
>  firstTwoRest = ModSurname.substr(2);
>  firstThree = ModSurname.substring(0,3);
>  firstThreeRest = ModSurname.substr(3);

>  if (ModSurname == "macauley" || ModSurname == "mackie" || ModSurname ==
> "machie" || ModSurname == "macken" || ModSurname == "mackey" || ModSurname
> == "macari" || ModSurname == "machon")
>  {
>   Except1 = ModSurname.substring(0,1); //first letter lower-case
>   UExcept1 = Except1.toUpperCase(); // first letter now capitalised
>   Except2 = ModSurname.substr(1); // rest of name

>   OutSurname = UExcept1 + Except2;
>  }

>  else if (firstThree == "mac") // format names with 'Mac' at start
>  {
>   if (ModSurname.length < 6)
>   {
>    MacShort1 = ModSurname.substring(0,1); //first letter lower-case
>    UMacShort1 = MacShort1.toUpperCase(); // first letter now capitalised
>    MacShort2 = ModSurname.substr(1); // rest of name

>    OutSurname = UMacShort1 + MacShort2;
>   }

>   else
>   {
>    OutSurname = UOther1 + Other2;
>    Mac1 = firstThree.substring(0,1); //'m' at start
>    UMac1 = Mac1.toUpperCase(); // now 'M'
>    Mac2 = firstThree.substr(1); // 'ac'
>    Macx1 = firstThreeRest.substring(0,1); // 'd'
>    UMacx1 = Macx1.toUpperCase(); //'D'
>    Macx2 = firstThreeRest.substr(1); //'onald'

>    OutSurname = UMac1 + Mac2 + UMacx1 + Macx2;
>   }
>  }

>  else if (firstTwo == "mc") // format names with 'Mc' at start
>  {
>   Mc1 = firstTwo.substring(0,1); //'m' at start
>   UMc1 = Mc1.toUpperCase(); // now 'M'
>   Mc2 = firstTwo.substr(1); // 'c'
>   Mcx1 = firstTwoRest.substring(0,1); // 'g'
>   UMcx1 = Mcx1.toUpperCase(); //'G'
>   Mcx2 = firstTwoRest.substr(1); //'uire'

>   OutSurname = UMc1 + Mc2 + UMcx1 + Mcx2;
>  }

>  else if (firstTwo == "o'") // format names with O' at start
>  {
>   O1 = firstTwo.substring(0,1); //'o' at start
>   UO1 = O1.toUpperCase(); // now 'o'
>   O2 = firstTwo.substr(1); // '''
>   Ox1 = firstTwoRest.substring(0,1); // 'd'
>   UOx1 = Ox1.toUpperCase(); //'D'
>   Ox2 = firstTwoRest.substr(1); //'onnell'

>   OutSurname = UO1 + O2 + UOx1 + Ox2;
>  }

>  else if (ModSurname.search("-") > -1) //search for double-barrelled name
> with hyphen
>  {
>   HyphenIndex = ModSurname.indexOf("-");
>   HPartOne = ModSurname.substring(0,HyphenIndex); //first part of dbl
> barrelled name
>   HPartTwo = ModSurname.substr(HyphenIndex + 1); //second part of dbl
> barrelled name

>   HPartOne1 = HPartOne.substring(0,1); //first letter lower-case
>   UHPartOne1 = HPartOne1.toUpperCase(); // first letter now capitalised
>   HPartOne2 = HPartOne.substr(1); // rest of name

>   HPartTwo1 = HPartTwo.substring(0,1); //first letter lower-case
>   UHPartTwo1 = HPartTwo1.toUpperCase(); // first letter now capitalised
>   HPartTwo2 = HPartTwo.substr(1); // rest of name

>   OutSurname = UHPartOne1 + HPartOne2 + "-" + UHPartTwo1 + HPartTwo2;
>  }

>  else if (ModSurname.search(" ") > -1) //search for double-barrelled name
> with space
>  {
>   SpaceIndex = ModSurname.indexOf(" ");
>   SPartOne = ModSurname.substring(0,SpaceIndex + 1); //first part of dbl
> barrelled name
>   SPartTwo = ModSurname.substr(SpaceIndex + 1); //second part of dbl
> barrelled name

>   SPartOne1 = SPartOne.substring(0,1); //first letter lower-case
>   USPartOne1 = SPartOne1.toUpperCase(); // first letter now capitalised
>   SPartOne2 = SPartOne.substr(1); // rest of name

>   SPartTwo1 = SPartTwo.substring(0,1); //first letter lower-case
>   USPartTwo1 = SPartTwo1.toUpperCase(); // first letter now capitalised
>   SPartTwo2 = SPartTwo.substr(1); // rest of name

>   OutSurname = USPartOne1 + SPartOne2 + " " + USPartTwo1 + SPartTwo2;
>  }

>  else
>  {
>   Other1 = ModSurname.substring(0,1); //first letter lower-case
>   UOther1 = Other1.toUpperCase(); // first letter now capitalised
>   Other2 = ModSurname.substr(1); // rest of name

>   OutSurname = UOther1 + Other2;
>  }

>  return(InTitle + " " + InInitial + " " + OutSurname);
> }



Sun, 27 Jun 2004 20:57:01 GMT  
 Help needed: Producing a mixed case surname....DONE!
This bombs on "Macintosh". UOther1 is not defined.

Quote:

> function make_MailingName(InTitle, InInitial, InSurname) // This function
> builds a mixed case 'Mailing Name', whatever the format of the surname
> {
>  var ModSurname = InSurname.toLowerCase();

>  firstTwo = ModSurname.substring(0,2);
>  firstTwoRest = ModSurname.substr(2);
>  firstThree = ModSurname.substring(0,3);
>  firstThreeRest = ModSurname.substr(3);

>  if (ModSurname == "macauley" || ModSurname == "mackie" || ModSurname ==
> "machie" || ModSurname == "macken" || ModSurname == "mackey" || ModSurname
> == "macari" || ModSurname == "machon")
>  {
>   Except1 = ModSurname.substring(0,1); //first letter lower-case
>   UExcept1 = Except1.toUpperCase(); // first letter now capitalised
>   Except2 = ModSurname.substr(1); // rest of name

>   OutSurname = UExcept1 + Except2;
>  }

>  else if (firstThree == "mac") // format names with 'Mac' at start
>  {
>   if (ModSurname.length < 6)
>   {
>    MacShort1 = ModSurname.substring(0,1); //first letter lower-case
>    UMacShort1 = MacShort1.toUpperCase(); // first letter now capitalised
>    MacShort2 = ModSurname.substr(1); // rest of name

>    OutSurname = UMacShort1 + MacShort2;
>   }

>   else
>   {
>    OutSurname = UOther1 + Other2;
>    Mac1 = firstThree.substring(0,1); //'m' at start
>    UMac1 = Mac1.toUpperCase(); // now 'M'
>    Mac2 = firstThree.substr(1); // 'ac'
>    Macx1 = firstThreeRest.substring(0,1); // 'd'
>    UMacx1 = Macx1.toUpperCase(); //'D'
>    Macx2 = firstThreeRest.substr(1); //'onald'

>    OutSurname = UMac1 + Mac2 + UMacx1 + Macx2;
>   }
>  }

>  else if (firstTwo == "mc") // format names with 'Mc' at start
>  {
>   Mc1 = firstTwo.substring(0,1); //'m' at start
>   UMc1 = Mc1.toUpperCase(); // now 'M'
>   Mc2 = firstTwo.substr(1); // 'c'
>   Mcx1 = firstTwoRest.substring(0,1); // 'g'
>   UMcx1 = Mcx1.toUpperCase(); //'G'
>   Mcx2 = firstTwoRest.substr(1); //'uire'

>   OutSurname = UMc1 + Mc2 + UMcx1 + Mcx2;
>  }

>  else if (firstTwo == "o'") // format names with O' at start
>  {
>   O1 = firstTwo.substring(0,1); //'o' at start
>   UO1 = O1.toUpperCase(); // now 'o'
>   O2 = firstTwo.substr(1); // '''
>   Ox1 = firstTwoRest.substring(0,1); // 'd'
>   UOx1 = Ox1.toUpperCase(); //'D'
>   Ox2 = firstTwoRest.substr(1); //'onnell'

>   OutSurname = UO1 + O2 + UOx1 + Ox2;
>  }

>  else if (ModSurname.search("-") > -1) //search for double-barrelled name
> with hyphen
>  {
>   HyphenIndex = ModSurname.indexOf("-");
>   HPartOne = ModSurname.substring(0,HyphenIndex); //first part of dbl
> barrelled name
>   HPartTwo = ModSurname.substr(HyphenIndex + 1); //second part of dbl
> barrelled name

>   HPartOne1 = HPartOne.substring(0,1); //first letter lower-case
>   UHPartOne1 = HPartOne1.toUpperCase(); // first letter now capitalised
>   HPartOne2 = HPartOne.substr(1); // rest of name

>   HPartTwo1 = HPartTwo.substring(0,1); //first letter lower-case
>   UHPartTwo1 = HPartTwo1.toUpperCase(); // first letter now capitalised
>   HPartTwo2 = HPartTwo.substr(1); // rest of name

>   OutSurname = UHPartOne1 + HPartOne2 + "-" + UHPartTwo1 + HPartTwo2;
>  }

>  else if (ModSurname.search(" ") > -1) //search for double-barrelled name
> with space
>  {
>   SpaceIndex = ModSurname.indexOf(" ");
>   SPartOne = ModSurname.substring(0,SpaceIndex + 1); //first part of dbl
> barrelled name
>   SPartTwo = ModSurname.substr(SpaceIndex + 1); //second part of dbl
> barrelled name

>   SPartOne1 = SPartOne.substring(0,1); //first letter lower-case
>   USPartOne1 = SPartOne1.toUpperCase(); // first letter now capitalised
>   SPartOne2 = SPartOne.substr(1); // rest of name

>   SPartTwo1 = SPartTwo.substring(0,1); //first letter lower-case
>   USPartTwo1 = SPartTwo1.toUpperCase(); // first letter now capitalised
>   SPartTwo2 = SPartTwo.substr(1); // rest of name

>   OutSurname = USPartOne1 + SPartOne2 + " " + USPartTwo1 + SPartTwo2;
>  }

>  else
>  {
>   Other1 = ModSurname.substring(0,1); //first letter lower-case
>   UOther1 = Other1.toUpperCase(); // first letter now capitalised
>   Other2 = ModSurname.substr(1); // rest of name

>   OutSurname = UOther1 + Other2;
>  }

>  return(InTitle + " " + InInitial + " " + OutSurname);
> }

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use of
this email address implies consent to these terms.



Mon, 28 Jun 2004 00:34:45 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help needed: Producing a mixed case surname...

2. Help needed on Select Case

3. Need Help Using the Case Statement

4. Help needed doing TrueType->Type42 conversion

5. need advice on mixing postscript with text in a form

6. need pointer re: mixing javascript and server controls...

7. "select...case", multiples cases not possible ?

8. Regexp and upper/lower case conversion example needed?

9. Select Case and Case 0 To 9

10. VBScript Select Case vs VB Select Case

11. Converting a Upper Case String to Upper and Lower Case

12. Need Cases in Point

 

 
Powered by phpBB® Forum Software