This helpful little ColdFusion function, removes all quotes from a string that is passed into it. It will remove single, double or both single and double quotes from a string that is passed into it.
-
<cffunction name="stripQuotes" access="public" output="false" returntype="string"
-
hint="Strips quotes from a string.">
-
<cfargument name="stripMe" type="string" required="true" hint="String from which to strip quotes."/>
-
<cfargument name="type" type="string" required="false" default="BOTH" hint="A list of the quote types to strip. Allowed values: SINGLE,DOUBLE, or BOTH. Ignores other values. Defaults to BOTH."/>
-
<cfset var stripChars = ""/>
-
<cfset var returnVal = arguments.stripMe/>
-
-
<cfswitch expression="#trim(arguments.type)#">
-
<cfcase value="SINGLE">
-
<cfset stripChars = "'"/>
-
</cfcase>
-
<cfcase value="DOUBLE">
-
<cfset stripChars = '"'/>
-
</cfcase>
-
<cfdefaultcase>
-
<cfset stripChars = '''"'/>
-
</cfdefaultcase>
-
</cfswitch>
-
-
<cfset returnVal = reReplace(arguments.stripMe, "[" & stripChars & "]", "", "ALL")/>
-
-
<cfreturn returnVal/>
-
</cffunction>