automatic capitalization

automatic capitalization

Page 1 of 1

5 Replies - 10107 Views - Last Post: 11 December 2009 - 03:07 PM Rate Topic: -----

#1 gnorton100  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 06-May 06

automatic capitalization

Posted 06 June 2006 - 09:26 AM

The Coldfusion form gets the first and last names and I use the code below to capitalize the data. It works great for names like Holmes and De Silva but for names with apostrophes, like O'Hare, which is rendered as O'hare. Note the "h" is not capitalized.

Can this code be modified to recognize apostrophes and capitalize the next letter ?

Thanks for the help.



  <cfif IsDefined("FORM.UserLastName") AND #FORM.UserLastName# NEQ "">
	<cfset sentence = "#FORM.UserLastName#">	
	<cfset sentence = UCase(Left(sentence, 1)) & LCase(Right(sentence, Len(sentence)-1))>
	<cfset found_at = REFind(" [[:lower:]]", sentence)>
	<cfloop condition="found_at">
		<cfset string_is = Mid(sentence, found_at, 2)>
		<cfset sentence = ReplaceNoCase(sentence, string_is, UCase(string_is), "ALL")>
		<cfset found_at = REFind(" [[:lower:]]", sentence)>
	</cfloop>
	<cfset sentenceULName = sentence>				
	'#sentenceULName#'
	<cfelse>
	NULL
  </cfif>




Is This A Good Question/Topic? 0
  • +

Replies To: automatic capitalization

#2 sandro  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 01-September 06

Re: automatic capitalization

Posted 03 September 2006 - 03:56 PM

View Postgnorton100, on 6 Jun, 2006 - 09:26 AM, said:

The Coldfusion form gets the first and last names and I use the code below to capitalize the data. It works great for names like Holmes and De Silva but for names with apostrophes, like O'Hare, which is rendered as O'hare. Note the "h" is not capitalized.

Can this code be modified to recognize apostrophes and capitalize the next letter ?

Thanks for the help.



  <cfif IsDefined("FORM.UserLastName") AND #FORM.UserLastName# NEQ "">
	<cfset sentence = "#FORM.UserLastName#">	
	<cfset sentence = UCase(Left(sentence, 1)) & LCase(Right(sentence, Len(sentence)-1))>
	<cfset found_at = REFind(" [[:lower:]]", sentence)>
	<cfloop condition="found_at">
		<cfset string_is = Mid(sentence, found_at, 2)>
		<cfset sentence = ReplaceNoCase(sentence, string_is, UCase(string_is), "ALL")>
		<cfset found_at = REFind(" [[:lower:]]", sentence)>
	</cfloop>
	<cfset sentenceULName = sentence>				
	'#sentenceULName#'
	<cfelse>
	NULL
  </cfif>




Hi gnorton100,

this is a very old post but since nobody has ever replied to it I thought it might still be a good idea to post an answer. Someone else might find it useful.
I added a few lines to your code to check for the " ' '" character and the whole script seems to work now.
o'brian will be O'Brian, o'connor will be O'Connor, da silva will still be Da Silva etc...

Here is the whole code with my commented modification:

 <cfif IsDefined("FORM.UserLastName") AND #FORM.UserLastName# NEQ "">
	<cfset sentence = "#FORM.UserLastName#">	
	<cfset sentence = UCase(Left(sentence, 1)) & LCase(Right(sentence, Len(sentence)-1))>
	<cfset found_at = REFind(" [[:lower:]]", sentence)>
	<cfloop condition="found_at">
		<cfset string_is = Mid(sentence, found_at, 2)>
		<cfset sentence = ReplaceNoCase(sentence, string_is, UCase(string_is), "ALL")>
		<cfset found_at = REFind(" [[:lower:]]", sentence)>
	</cfloop>
	<!---********************BEGINNING OF MODIFICATION *************************
	Searching for the character " ' " in the string in the textfield and assign its index position to noRefoun_at variable
	the condition checks if the " ' " character has been found and replace the character at the index following the " ' " with the
	UPPERCASE version of the same character.
	 --->
	<cfset noREfound_at = Find("'", sentence, 1) />
	<cfif noREfound_at NEQ 0>
	<cfset sentence = Replace(sentence, Mid(sentence, noREfound_at+1,1), Ucase(Mid(sentence, noREfound_at+1,1)), "all") />
	</cfif>
	<!--- ********************END OF MODIFICATION *************************--->
	<cfset sentenceULName = sentence>			  
	<cfoutput>#sentenceULName#</cfoutput>
	<cfelse>
	NULL
  </cfif>



Hope this helps

Sandro
Was This Post Helpful? 0
  • +
  • -

#3 blair_one  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 12-March 07

Re: automatic capitalization

Posted 12 March 2007 - 05:46 AM

View Postsandro, on 3 Sep, 2006 - 03:56 PM, said:

View Postgnorton100, on 6 Jun, 2006 - 09:26 AM, said:

The Coldfusion form gets the first and last names and I use the code below to capitalize the data. It works great for names like Holmes and De Silva but for names with apostrophes, like O'Hare, which is rendered as O'hare. Note the "h" is not capitalized.

Can this code be modified to recognize apostrophes and capitalize the next letter ?

Thanks for the help.



  <cfif IsDefined("FORM.UserLastName") AND #FORM.UserLastName# NEQ "">
	<cfset sentence = "#FORM.UserLastName#">	
	<cfset sentence = UCase(Left(sentence, 1)) & LCase(Right(sentence, Len(sentence)-1))>
	<cfset found_at = REFind(" [[:lower:]]", sentence)>
	<cfloop condition="found_at">
		<cfset string_is = Mid(sentence, found_at, 2)>
		<cfset sentence = ReplaceNoCase(sentence, string_is, UCase(string_is), "ALL")>
		<cfset found_at = REFind(" [[:lower:]]", sentence)>
	</cfloop>
	<cfset sentenceULName = sentence>				
	'#sentenceULName#'
	<cfelse>
	NULL
  </cfif>




Hi gnorton100,

this is a very old post but since nobody has ever replied to it I thought it might still be a good idea to post an answer. Someone else might find it useful.
I added a few lines to your code to check for the " ' '" character and the whole script seems to work now.
o'brian will be O'Brian, o'connor will be O'Connor, da silva will still be Da Silva etc...

Here is the whole code with my commented modification:

 <cfif IsDefined("FORM.UserLastName") AND #FORM.UserLastName# NEQ "">
	<cfset sentence = "#FORM.UserLastName#">	
	<cfset sentence = UCase(Left(sentence, 1)) & LCase(Right(sentence, Len(sentence)-1))>
	<cfset found_at = REFind(" [[:lower:]]", sentence)>
	<cfloop condition="found_at">
		<cfset string_is = Mid(sentence, found_at, 2)>
		<cfset sentence = ReplaceNoCase(sentence, string_is, UCase(string_is), "ALL")>
		<cfset found_at = REFind(" [[:lower:]]", sentence)>
	</cfloop>
	<!---********************BEGINNING OF MODIFICATION *************************
	Searching for the character " ' " in the string in the textfield and assign its index position to noRefoun_at variable
	the condition checks if the " ' " character has been found and replace the character at the index following the " ' " with the
	UPPERCASE version of the same character.
	 --->
	<cfset noREfound_at = Find("'", sentence, 1) />
	<cfif noREfound_at NEQ 0>
	<cfset sentence = Replace(sentence, Mid(sentence, noREfound_at+1,1), Ucase(Mid(sentence, noREfound_at+1,1)), "all") />
	</cfif>
	<!--- ********************END OF MODIFICATION *************************--->
	<cfset sentenceULName = sentence>			  
	<cfoutput>#sentenceULName#</cfoutput>
	<cfelse>
	NULL
  </cfif>



Hope this helps

Sandro


--

Sandro, I think you just need to change this line ("all" should be "1") otherwise you get O'RouRke:

<cfset sentence = Replace(sentence, Mid(sentence, noREfound_at+1,1), Ucase(Mid(sentence, noREfound_at+1,1)), "1") />

-Blair
Was This Post Helpful? 0
  • +
  • -

#4 pixelwiz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-July 09

Re: automatic capitalization

Posted 10 August 2009 - 11:43 AM

Hi All,

What about handling Mc/Mac like in MacArthur or McCoppin?

-Roman
Was This Post Helpful? 0
  • +
  • -

#5 chiponium  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-December 09

Re: automatic capitalization

Posted 04 December 2009 - 07:52 PM

<cfif IsDefined("FORM.UserLastName") AND #FORM.UserLastName# NEQ "">
	<cfset sentence = "#FORM.UserLastName#">	
	<cfset sentence = UCase(Left(sentence, 1)) & LCase(Right(sentence, Len(sentence)-1))>
	<cfset found_at = REFind(" [[:lower:]]", sentence)>
	<cfloop condition="found_at">
		<cfset string_is = Mid(sentence, found_at, 2)>
		<cfset sentence = ReplaceNoCase(sentence, string_is, UCase(string_is), "ALL")>
		<cfset found_at = REFind(" [[:lower:]]", sentence)>
	</cfloop>
	<!---********************BEGINNING OF MODIFICATION *************************
	Searching for the character " ' " in the string in the textfield and assign its index position to noRefoun_at variable
	the condition checks if the " ' " character has been found and replace the character at the index following the " ' " with the
	UPPERCASE version of the same character.
	 --->
	<cfset noREfound_at = Find("'", sentence, 1) />
<cfif noREfound_at NEQ 0>
	<cfset sentence = Replace(sentence, Mid(sentence, noREfound_at+1,1), Ucase(Mid(sentence, noREfound_at+1,1)), "all") />

<!---Modified for Mc and Mac Capitalization of Last names.  chiponium 11/09--->
<cfelseif noREfound_at EQ 0>
	<cfset noREfound_at = Find("Mc", sentence, 1) />
		<cfif noREfound_at NEQ 0>
		  <cfset sentence = Replace(sentence, Mid(sentence, noREfound_at+2,1), Ucase(Mid(sentence, noREfound_at+2,1)), "all") />	
		<cfelseif noREfound_at EQ 0>
		  <cfset noREfound_at = Find("Mac", sentence, 1) />
		  <cfset sentence = Replace(sentence, Mid(sentence, noREfound_at+3,1), Ucase(Mid(sentence, noREfound_at+3,1)), 1) />	
		</cfif>
</cfif>
  
	<!--- ********************END OF MODIFICATION *************************--->
	<cfset sentenceULName = sentence>			  
	<cfoutput>#sentenceULName#</cfoutput>
	<cfelse>
	NULL
  </cfif>


Was This Post Helpful? 0
  • +
  • -

#6 chiponium  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-December 09

Re: automatic capitalization

Posted 11 December 2009 - 03:07 PM

I also added this bit of code (above the section where it starts to look for " ' " apostrophes) to capitalize the next letter after a hyphenated last name.


<cfset noREfound_at = Find("-", sentence, 1) />
<cfif noREfound_at NEQ 0>
	<cfset sentence = Replace(sentence, Mid(sentence, noREfound_at+1,1), Ucase(Mid(sentence, noREfound_at+1,1)), "all") />
</cfif>

<cfset noREfound_at = Find("'", sentence, 1) />
<cfif noREfound_at NEQ 0>
	<cfset sentence = Replace(sentence, Mid(sentence, noREfound_at+1,1), Ucase(Mid(sentence, noREfound_at+1,1)), "all") /> ...





Chip :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1