Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Function (Linecase.ahk) case fixes Mc and O' to correct upper/lower


  • Please log in to reply
No replies to this topic
Trubbleguy
  • Members
  • 122 posts
  • Last active: Jan 15 2017 10:50 AM
  • Joined: 20 Jan 2007

I got fed up of my names databases being the wrong case when it came to names like O'Grady or McNight so i coded a little function to deal with it.

 

If A_Scriptname=linecase.ahk 
{
; demo code that only runs while testing this module	
msgbox % linecase("mcnamara") "`n" linecase("o'grady") "`n" linecase("mcclure")
exitapp
}

linecase(name)
	{
	StringLower,name,name
	uc=1
	nnp=
	pl=
	Loop,Parse,name,
		{
		letter:=A_LoopField
		If uc=1
			{
			StringUpper,letter,A_LoopField
			uc=
			}
		If letter in,%A_Space%,.,-,',(,c,
			{
			If A_Index=1
				If letter=c
					{
					nnp.=letter
					pl:=letter
					uc=
					Continue
					}
			If A_Index >=2
				{
				If letter=c
					If pl not in,m
						{
						mhit=
						uc=
						nnp.=letter
						pl:=letter
						Continue
						}
				If letter='
					If pl not in,o
						{
						mhit=
						uc=
						nnp.=letter
						pl:=letter
						Continue
						}
				uc++
				nnp.=letter
				pl:=letter
				Continue
				}
			}
		nnp.=letter
		pl:=letter
		}
	return nnp
	}