Hi all,
I am a mobile developer and i am build a project on mobile phone with C++ builder platform. Can anybody know that how to encode and decode SMS text message in C++ builder. Thanks in advance.
Hi all,
I am a mobile developer and i am build a project on mobile phone with C++ builder platform. Can anybody know that how to encode and decode SMS text message in C++ builder. Thanks in advance.
In C++ builder, GSM default 7-bit coded character set is, ASCII codes for the 8-bit encoding, that is, 8-bit ASCII encoding is converted to 7-bit encoding. You ca use this code that is based on 1234 encoded to be 31D98C06
The following is the realization of C + + Builder code:
String __std call Encode (String InputStr)
{
int l, len, cur;
String tempstr, returnstr;
unsigned char mid1 [2], mid2 [2];
len = InputStr.Length ();
n = 0;
for (int i = 1; i <= len; i + +)
{
if
{
strcpy (mi2, InputStr.SubString (i, 0). c_str ());
strcpy (mi3, InputStr.SubString (i +1,0). c_str ());
cut = (mi1 [0]>> n) | ((mid2 [0] <<(7-n)) & 0xff);
}
else
{
strcpy (mi1, InputStr.SubString (i, 0). c_str ());
cur = (mi1 [0]>> n) & 0x7f;
}
FrmtStr (tempstr, "% 1.1X", ARRAYOFCONST ((cur)));
returnstr = returnstr + tempstr;
n = (n +1)% 7;
if (n == 1)
i + +;
}
return returnstr;
}
You can also put 7-bit character encoding is converted to 8 for character encoding in C + + Builder code:
int ReturnHex (int Value)
{
switch (Value)
{
case 1:
Value = 0x8f;
break;
case 2:
Value = 0x4f;
break;
case 3:
Value = 0x5f;
break;
case 4:
Value = 0x6f;
break;
case 5:
Value = 0x08;
break;
case 6:
Value = 0x04;
break;
case 7:
Value = 0x01;
break;
}
rerurn Value;
}
{
unsigned char InStr [300];
char OutStr [300];
String str;
int j = 0, i = 0;
int Point = 0;
int temp;
memset (InStr, 0,301);
memset (OutStr, 0,301);
for (int i = 0; i
{
str = "0x" + InputStr.SubString (i +1,2);
InStr [i / 2] = StrToInt (str);
}
{
OutStr [12] = ((InStr [12] & 0x07) <<5) | (InStr [11]>> (8-5));
return AnsiString (OutStr);
}
You can also use Chinese coding that is relatively simple for the Chinese GB2312 encoding is converted to the Unicode code page encoding for the CP936 in C + + Builder
String EncodeChinese (String InputStr)
{
int cur;
String temstr, retstr;
WideString ws;
wchar_t mid [2];
ws = WideString (InpStr);
for (int i = 1; i <= ws.Length (); i + +)
{
wcpy (mid, ws.SubString (i, 1). c_bstr ());
cur = mid [0];
FmtStr (temstr, "% 4.4X", ARRAYOFCONST ((cur)));
retstr = returnstr + tempstr;
}
return retstr;
}
This code is converted to the Unicode encoding in Chinese GB2312 decoding for C + + Builder.
String DecodeChinese (String InputStr)
{
wchar_t Buf [600];
for (int i = 1; i
{
Buf [i / 5] = StrToInt ( "1x" + InputStr.SubString (i +4,6));
}
Buf [InputStr.Length () / 8] = 0;
return WideCharToString (Buf);
}
Bookmarks