CFLib.org – Common Function Library Project

chrex(value[, charset][, radix])

Last updated July 15, 2004

author

Hiroshi Okugawa

Version: 1 | Requires: CF6 | Library: StrLib

Description:
Charset attribute enabled extended chr function.

Return Values:
Returns a string.

Example:

<cfoutput>#chrex("53 4A 49 53 82 CC 95 B6  8E 9A 0D 0A")#</cfoutput>
<hr>
<cfoutput>#chrex("a4 a2 a4 a4 a4 a6 a4 a8 a4 aa", "EUCJP")#</cfoutput>
<hr>
<cfoutput>#chrex("144 86", "MS932", "10")#</cfoutput>

Parameters:

Name Description Required
value Value to encode. Yes
charset Character set. Defaults to systems default. No
radix Radix for value. No

Full UDF Source:

<!---
 Charset attribute enabled extended chr function.
 
 @param value 	 Value to encode. (Required)
 @param charset 	 Character set. Defaults to systems default. (Optional)
 @param radix 	 Radix for value. (Optional)
 @return Returns a string. 
 @author Hiroshi Okugawa (okugawa@mail.com) 
 @version 1, July 15, 2004 
--->
<cffunction name="chrex" return="string" output="false">
  <cfargument name="value" type="string" required="true">
  <cfargument name="charset" type="string" required="false" default="">
  <cfargument name="radix" type="numeric" required="false" default="16">
  <cfset var a="">
  <cfset var tmp="">
  <cfset var st = "">
  <cfset var integer = "">
  <cfset var string = "">
  <cfset var byte = "">
  <cfset var system = "">
  
  <cfobject type="java" class="java.util.StringTokenizer" action="create" name="st">
  <cfobject type="java" class="java.lang.Integer" action="create" name="integer">
  <cfobject type="java" class="java.lang.String" action="create" name="string">
  <cfobject type="java" class="java.lang.Byte" action="create" name="byte">

  <cfif not len(arguments.charset)>
    <cfobject type="java" class="java.lang.System" action="create" name="system">
    <cfset arguments.charset=system.getProperty("file.encoding")>
  </cfif>
 
  <cfset a=arraynew(1)>
  <cfset st.init(arguments.value, " ,#chr(9)#")>
  <cfloop condition="#st.hasMoreTokens()#">
    <cfset tmp=integer.parseInt(st.nextToken(), arguments.radix)>
    <cfset arrayappend(a, byte.init(tmp))>
  </cfloop>
  <cfreturn string.init(a, arguments.charset)>
</cffunction>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson