I need to send extended chars as | ^ € { } [ ~ ] \ without using unicode because when I use unicode message maxlength becomes much shorter than initial 160 chars, so one message is splitted in two or more messages, and that has a cost.
Is there any solution?
Thank you a lot.
How to send special chars(Extended Charset)?
Moderator: alt
GSM 03.38 / ASCII Encoder
Use the below function to generate your ShortMessageBytes and change the DataEncoding to ASCII (GSM03.38).
i.e. req.ShortMessageBytes = GSMEncode("!£$%^&*()€");
public static byte[] GSMEncode(string PlainText)
{
// ` is not a conversion, just a untranslatable letter.
// x0D should be CR but this causes double linefeed on
// some phones so has been removed.
const string strGSMTable =
"@£$¥èéùìòÇ\nØø`Åå" +
"Δ_ΦΓΛΩΠΨΣΘΞ`ÆæßÉ" +
" !\"#¤%&'()*+,-./" +
"0123456789:;<=>?" +
"¡ABCDEFGHIJKLMNO" +
"PQRSTUVWXYZÄÖÑÜ`" +
"¿abcdefghijklmno" +
"pqrstuvwxyzäöñüà";
const string strExtendedTable =
"````````````````" +
"````^```````````" +
"````````{}`````\\" +
"````````````[~]`" +
"|```````````````" +
"````````````````" +
"`````€``````````" +
"````````````````";
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
foreach (char cPlainText in PlainText.ToCharArray())
{
if (cPlainText != '`') // Ignore `
{
int intGSMTable = strGSMTable.IndexOf(cPlainText);
if (intGSMTable != -1)
{
ms.WriteByte((byte)intGSMTable);
continue;
}
int intExtendedTable = strExtendedTable.IndexOf(cPlainText);
if (intExtendedTable != -1)
{
ms.WriteByte(27);
ms.WriteByte((byte)intExtendedTable);
}
}
}
ms.Close();
return ms.ToArray();
}
}
i.e. req.ShortMessageBytes = GSMEncode("!£$%^&*()€");
public static byte[] GSMEncode(string PlainText)
{
// ` is not a conversion, just a untranslatable letter.
// x0D should be CR but this causes double linefeed on
// some phones so has been removed.
const string strGSMTable =
"@£$¥èéùìòÇ\nØø`Åå" +
"Δ_ΦΓΛΩΠΨΣΘΞ`ÆæßÉ" +
" !\"#¤%&'()*+,-./" +
"0123456789:;<=>?" +
"¡ABCDEFGHIJKLMNO" +
"PQRSTUVWXYZÄÖÑÜ`" +
"¿abcdefghijklmno" +
"pqrstuvwxyzäöñüà";
const string strExtendedTable =
"````````````````" +
"````^```````````" +
"````````{}`````\\" +
"````````````[~]`" +
"|```````````````" +
"````````````````" +
"`````€``````````" +
"````````````````";
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
foreach (char cPlainText in PlainText.ToCharArray())
{
if (cPlainText != '`') // Ignore `
{
int intGSMTable = strGSMTable.IndexOf(cPlainText);
if (intGSMTable != -1)
{
ms.WriteByte((byte)intGSMTable);
continue;
}
int intExtendedTable = strExtendedTable.IndexOf(cPlainText);
if (intExtendedTable != -1)
{
ms.WriteByte(27);
ms.WriteByte((byte)intExtendedTable);
}
}
}
ms.Close();
return ms.ToArray();
}
}