GSM7 Encoding in C#

Text messages are generally written in a 7 bit alphabet, unless you are sending a text in Hebrew, Chinese, Japanese, Arabic or Korean.

It is also referred to as GSM 03.38.

This 7 Bit alphabet comprises 127 letters, including accents common to German, Italian, French and Scandinavian languages. It also

may contain a subset of Greek letters.

The Alphabet is expandable to cover newly added letters, such as the euro symbol (€) which has only came in common usage since the 1st of January 1999. Almost 10 years after the introduction of the GSM standard. The expansion comes through the use of the escape symbol (ASCII 27, HEX 1B). Where {Escape} + e becomes €.

This code in C# converts from plain text into GSM7 Encoding, including expansion sets.

GSM7 Encoding C#

public static string GSMChar(string PlainText)

{

// ` is not a conversion, just a untranslatable letter

string strGSMTable ="";

strGSMTable += "@£$¥èéùìòÇ`Øø`Åå";

strGSMTable += "Δ_ΦΓΛΩΠΨΣΘΞ`ÆæßÉ";

strGSMTable += " !\"#¤%&'()*=,-./";

strGSMTable += "0123456789:;<=>?";

strGSMTable += "¡ABCDEFGHIJKLMNO";

strGSMTable += "PQRSTUVWXYZÄÖÑÜ`";

strGSMTable += "¿abcdefghijklmno";

strGSMTable += "pqrstuvwxyzäöñüà";

string strExtendedTable = "";

strExtendedTable += "````````````````";

strExtendedTable += "````^```````````";

strExtendedTable += "````````{}`````\\";

strExtendedTable += "````````````[~]`";

strExtendedTable += "|```````````````";

strExtendedTable += "````````````````";

strExtendedTable += "`````€``````````";

strExtendedTable += "````````````````";

string strGSMOutput = "";

foreach(char cPlainText in PlainText.ToCharArray())

{

int intGSMTable = strGSMTable.IndexOf(cPlainText);

if (intGSMTable != -1)

{

strGSMOutput += intGSMTable.ToString("X2");

continue;

}

int intExtendedTable = strExtendedTable.IndexOf(cPlainText);

if (intExtendedTable !=-1)

{

strGSMOutput += (27).ToString("X2");

strGSMOutput += intExtendedTable.ToString("X2");

}

}

return strGSMOutput;

}