The above code I shared will check the whole Idoc for special characters you hard coded and replace it with null value.
This is not a udf, you have to create a java map using imported archive and apply it in operation mapping before message mapping...follow the link shared by Hareesh above on how to create a java map.
Let me know if you have any questions!!
Thanks
Navneet.