Skip to content

Instantly share code, notes, and snippets.

@JamoCA
Created April 28, 2023 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamoCA/ae63641dc0fdd5138cc8b2f5ee92f032 to your computer and use it in GitHub Desktop.
Save JamoCA/ae63641dc0fdd5138cc8b2f5ee92f032 to your computer and use it in GitHub Desktop.
Sample ColdFusion on how to remove high ascii from strings
<!--- 20230428 https://stackoverflow.com/questions/76120058/removing-unicode-invalid-characters-from-string
Try this at TryCF.com
--->
<cfoutput>
<cfset k = "E�l�e�c�t�r�o�n�i�c">
<div><b>original:</b> #k#</div>
<cfset k2 = rereplace(k, "[^\x20-\x7E]", "", "ALL")>
<div><b>rereplace:</b> #k2#</div>
<cfset k3 = createObject( 'java', 'java.text.Normalizer' ).normalize( k, createObject( 'java', 'java.text.Normalizer$Form' ).valueOf('NFD') ).replaceAll('\p{InCombiningDiacriticalMarks}+','').replaceAll('[^\p{ASCII}]+','')>
<div><b>java.text.Normalizer:</b> #k3#</div>
</cfoutput>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment