[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

How to add UCASE after a slash in coldfusion

Im outputing text from a db that is all uppercase example "ACCOUNTING/FUNDAMENTALS" and I need ColdFusion to only make the beginning letter Upper case as well as the beginning letter after a slash like this "Accounting/Fundamentals". The code below is an example of what I need but its not correct.
<!--- Might need logic like this ---, but not sure --->
<cfif COURSE_TITLE_FINAL CONTAINS "/">
    <cfset COURSE_TITLE_FINAL = UCase(Left(COURSE_TITLE_FINAL, 1)) & LCase(Right(COURSE_TITLE_FINAL, Len(COURSE_TITLE_FINAL)-1))>
    </cfif>

Open in new window

0
tribalboy3000
Asked:
tribalboy3000
1 Solution
 
SidFishesCommented:
this is probably easier in a regex but this works

<cfset COURSE_TITLE_FINAL = "ACCOUNTING/FUNDAMENTALS">

<cfif find("/",COURSE_TITLE_FINAL)>
<cfset U1 = Ucase(Left(COURSE_TITLE_FINAL, 1))>
<cfset U2 = Ucase(left(Listlast(COURSE_TITLE_FINAL,"/"), 1))>
<cfset l1 = lcase(right(listfirst(COURSE_TITLE_FINAL,"/"),len(listfirst(COURSE_TITLE_FINAL,"/"))-1))>
<cfset l2 = lcase(right(COURSE_TITLE_FINAL,len(Listlast(COURSE_TITLE_FINAL,"/"))-1))>
 <cfset COURSE_TITLE_FINAL = u1 & l1 & "/" & u2 & l2>
</cfif>
<cfoutput>
  #COURSE_TITLE_FINAL#
</cfoutput>
0
 
Jones911Commented:
Can be done in one line but this will work.
<cfset COURSE_TITLE_FINAL = "ACCOUNTING/FUNDAMENTALS" />
<cfif COURSE_TITLE_FINAL CONTAINS "/">
	<cfset string = makeUpper(listGetAt(COURSE_TITLE_FINAL,1,"/")) & "/" & makeUpper(listGetAt(COURSE_TITLE_FINAL,2,"/")) />
</cfif>
<cfdump var="#string#"/>
 
 
<cffunction name="makeUpper" returntype="string">
	<cfargument name="mixedString" required="true" />
    <cfreturn ucase(left(lcase(arguments.mixedString),1)) &  right(lcase(arguments.mixedString),len(arguments.mixedString)-1) />
    
</cffunction>

Open in new window

0
 
tribalboy3000Author Commented:
Thanks
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now