Question
Uppercase script help
Hello I am trying to capitalize the first letter of address
lines in my db also the first letter after a space. Here is the
code I was using for it. but there seems to be a problem with a few
strings that to me I can't see the problem with. Please Look at the
code below and let me know if you see the problem.
<cffunction name="FirstUpperCase">
<cfargument name="string" required="Yes" type="string">
<cfset var returnString = ' '>
<cfloop from="1" to="#ListLen(ARGUMENTS.string, ' ')#" index="i">
<cfset listItem = ListGetAt(ARGUMENTS.string, i, ' ')>
<cfset returnString = returnString & UCase(Left(listItem, 1)) & LCase(Right(listItem, (Len(listItem) - 1)))> <cfif i LT ListLen(ARGUMENTS.string, ' ')>
<cfset returnString = returnString & ' '>
</cfif>
</cfloop>
<cfreturn returnString></cffunction>
<cfoutput>#FirstUpperCase(Recordset.address)#</cfoutput>
Here is the error:
Parameter 2 of function Right which is now 0 must be a positive integer
The error occurred in C:\CFusionMX7\wwwroot\WLWK\Members\members.cfm: line 21
19 : <cfset listItem = ListGetAt(ARGUMENTS.string, i, ' ')>
20 : <!--- this does all of the conversion to count characters and only make the first one cap. --->
21 : <cfset returnString = returnString & UCase(Left(listItem, 1)) & LCase(Right(listItem, (Len(listItem) - 1)))>
22 : <!--- This basically checks if the string is now less then the original string which it always will be.--->
23 : <cfif i LT ListLen(ARGUMENTS.string, ' ')>
Here is the string it bombs on:
1301 Jonesmont Rd Apt 7
Is it because the last character is only one character long? How would I fix this?
Thanks,
Andrew
<cffunction name="FirstUpperCase">
<cfargument name="string" required="Yes" type="string">
<cfset var returnString = ' '>
<cfloop from="1" to="#ListLen(ARGUMENTS.string, ' ')#" index="i">
<cfset listItem = ListGetAt(ARGUMENTS.string, i, ' ')>
<cfset returnString = returnString & UCase(Left(listItem, 1)) & LCase(Right(listItem, (Len(listItem) - 1)))> <cfif i LT ListLen(ARGUMENTS.string, ' ')>
<cfset returnString = returnString & ' '>
</cfif>
</cfloop>
<cfreturn returnString></cffunction>
<cfoutput>#FirstUpperCase(Recordset.address)#</cfoutput>
Here is the error:
Parameter 2 of function Right which is now 0 must be a positive integer
The error occurred in C:\CFusionMX7\wwwroot\WLWK\Members\members.cfm: line 21
19 : <cfset listItem = ListGetAt(ARGUMENTS.string, i, ' ')>
20 : <!--- this does all of the conversion to count characters and only make the first one cap. --->
21 : <cfset returnString = returnString & UCase(Left(listItem, 1)) & LCase(Right(listItem, (Len(listItem) - 1)))>
22 : <!--- This basically checks if the string is now less then the original string which it always will be.--->
23 : <cfif i LT ListLen(ARGUMENTS.string, ' ')>
Here is the string it bombs on:
1301 Jonesmont Rd Apt 7
Is it because the last character is only one character long? How would I fix this?
Thanks,
Andrew
