Created
April 28, 2023 15:18
-
-
Save JamoCA/ae63641dc0fdd5138cc8b2f5ee92f032 to your computer and use it in GitHub Desktop.
Sample ColdFusion on how to remove high ascii from strings
This file contains 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
<!--- 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