-
-
Save ivanionut/199a2e1bebaede1fb160 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cffunction name="MidLeft" returntype="string" output="no" hint="Returns numChars characters from the left side of startPos in the string"> | |
<cfargument name="stringVal" type="string" required="yes" default=""> | |
<cfargument name="startPos" type="numeric" required="yes" default="1"> | |
<cfargument name="numChars" type="numeric" required="yes" default="0"> | |
<!--- If startPos exceeds length of string argument then start picking characters from string end position ---> | |
<cfif arguments.startPos gt len(arguments.stringVal)> | |
<cfset arguments.startPos = len(arguments.stringVal)> | |
</cfif> | |
<cfset var fromPos = arguments.startPos - arguments.numChars + 1> | |
<!--- Avoid 2nd parameter of mid function to goto 0 or below that ---> | |
<cfif arguments.startPos - arguments.numChars + 1 lte 0> | |
<cfset fromPos = 1> | |
<cfset arguments.numChars = arguments.startPos> | |
</cfif> | |
<cfreturn mid(arguments.stringVal, fromPos, arguments.numChars)> | |
</cffunction> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment