Muhammad Atif Agha
Muhammad Atif Agha

Reputation: 1545

Proper text encoding for GSM Pdu 7Bit to avoid chars like “

I have a sending sms website, and when any user sends a message having “ or such similar characters, it does not accept it and create problems, that this character is not allowed in GSM 7Bit class. Can you please explain, how to remove or translate such characters into valid ascii characters in c#.net. Fore example “ is "

Thanks

Upvotes: 0

Views: 1433

Answers (2)

Kemal Atik
Kemal Atik

Reputation: 337

I guess the goal is to check if all characters of entered message are the member of GSM 7 bit encoding table.

public static boolean isGSM7Bit(String message)
{
Pattern pattern = Pattern.compile("^[A-Za-z0-9 \\r\\n@£$¥èéùìòÇØøÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ!\"#$%&'()*+,\\-./:;<=>?¡ÄÖÑܧ¿äöñüà^{}\\\\\\[~\\]|€]*$");
Matcher matcher = pattern.matcher(message);
return matcher.matches();
}

Upvotes: 1

James Manning
James Manning

Reputation: 13579

Whenever you're taking the string and encoding it into bytes for sending, use Encoding.ASCII

Upvotes: 2

Related Questions