I am looking for suggestions/help with SMS message...
# cfml-general
a
I am looking for suggestions/help with SMS messages. We use the ckeditor to generate emails and SMS messages. Then we run the text through a regex to remove all HTML. Since we recently changed SMS providers, now our SMS message count has increased a lot due to non-GSM characters in the message. The provider we use is converting the special non-GSM characters to images causing the SMS counts to be much larger then expected. Is there anyway to convert non-GSM characters to an equivalent GSM character in Java or ColdFusion before sending the messages to the SMS provider?
b
Can you be more specific about what characters you're talking about?
If you just want to remove accents from text (like turn a spanish Ñ into an N then there are libs that do that
Here is a similar function I've used to clean crazy chars from file names
Copy code
function cleanFileName( str ) {
		str = str.urlDecode().urlDecode();
		var Normalizer = createObject("java","java.text.Normalizer");
		var NormalizerForm = createObject("java","java.text.Normalizer$Form");
		var normalizedString = Normalizer.normalize(str, createObject("java","java.text.Normalizer$Form").NFD);
		var pattern = createObject("java","java.util.regex.Pattern").compile("\p{InCombiningDiacriticalMarks}+");
		str = pattern.matcher(normalizedString).replaceAll("");
		return str.reReplaceNoCase( '[^a-zA-Z0-9-_ \.&\+\$@]', '_', 'all' )
	}
👍🏼 1
The
java.text.Normalizer
class specifically is what does character replacement
👍🏼 1
a
Yes, we deal with Spanish and Hawaiian languages that have letters not part of the GSM character set https://en.wikipedia.org/wiki/GSM_03.38
I would start with that normalizer class and see how close it gets you
a
Thank you for the fast response. I will give that a try
b
You can basically grab that UDF I pasted and just remove the last line which is removing chars I specifically didn't want in file names, but that probablayk doesn't apply to you
g
So you need to convert text to ASCII7? I use a JUnidecode library to do this and it does a great job. Here's my blog post regarding it. https://dev.to/gamesover/convert-unicode-strings-to-ascii-with-coldfusion-junidecode-lhf
a
Thanks @gamesover I will consider your option too. Appreciate the help and suggestion.
e
Just use the CHR tag, 🙂 Granted someone will eventually need to read your code and scream, but until then.