手机短信息的编解码源代码

上传人:子 文档编号:42495331 上传时间:2018-06-02 格式:DOC 页数:8 大小:42KB
返回 下载 相关 举报
手机短信息的编解码源代码_第1页
第1页 / 共8页
手机短信息的编解码源代码_第2页
第2页 / 共8页
手机短信息的编解码源代码_第3页
第3页 / 共8页
手机短信息的编解码源代码_第4页
第4页 / 共8页
手机短信息的编解码源代码_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《手机短信息的编解码源代码》由会员分享,可在线阅读,更多相关《手机短信息的编解码源代码(8页珍藏版)》请在金锄头文库上搜索。

1、using System; using System.Text;namespace jace.CN.SMSLib / / By popcorn 2004.5。 / / public class CNText public CNText() / / 编码格式 / public enum GSMCode Bit7=0, Bit8=1, UCS2=2 / / 对整个短信息进行解码 / / 要解码的信息 / 解码后的电话号码 / 解码后的短信内容 / 短信时间戳 / 使用的编码方式 / 短信中心号 / 成功返回 true static public bool DecodingMsg(string s

2、,ref string phone,ref string text,ref DateTime sendTime,ref GSMCode code,ref string SCA) try /短信息中心 int iLength=int.Parse(s.Substring(0,2),System.Globalization.NumberStyles. AllowHexSpecifier); if(iLength0) if(s.Substring(2,2)=“91“) SCA+=“+“; iLength-; for(int i=0;i / 对短信息中心进行编码 / / 要编码的号码 / 编码后的号码

3、static public string EncodingSCA(string s) StringBuilder sb=new StringBuilder(); if(s.Length=0) sb.Append(“00“); return sb.ToString(); if(s.StartsWith(“+“) sb.Append(“91“); /用国际格式号码(在前面加+) s=s.Remove(0,1); else sb.Append(“C8“); if(s.Length%2=1)s+=“F“; for(int i=0;i / 对电话号码进行编码 / / 要编码的电话号码 / 编码后的电话号

4、码 static public string EncodingNumber(string mobileNo) StringBuilder sb=new StringBuilder(); if(mobileNo.StartsWith(“+“) sb.Append(“91“); mobileNo=mobileNo.Remove(0,1); else sb.Append(“C8“); string len=mobileNo.Length.ToString(“X2“); if(mobileNo.Length%2=1)mobileNo+=“F“; for(int i=0;i / 使用 7-bit 进行编

5、码 / / 要编码的英文字符串 / 信息长度及编码后的字符串 static public string EncodingBit7(string s) int iLeft=0; string sReturn=“; StringBuilder sb=new StringBuilder(); for(int i=0;i iChar; / 修改目标串的指针和计数值 pDst+; sb.Append(sReturn.Substring(2,2); sb.Append(sReturn.Substring(0,2); return (sb.Length/2).ToString(“X2“)+sb.ToStri

6、ng(); / / 对 7-bit 编码进行解码 / / 要解码的字符串 / 解码后的英文字符串 static public string DecodingBit7(string s) int iByte=0; int iLeft=0; / 将源数据每 7 个字节分为一组,解压缩成 8 个字节 / 循环该处理过程,直至源数据被处理完 / 如果分组不到 7 字节,也能正确处理 System.Text.StringBuilder sb=new System.Text.StringBuilder();for(int i=0;i (7-iByte); / 修改字节计数值 iByte+; / 到了一组的

7、最后一个字节 if(iByte = 7) / 额外得到一个目标解码字节 sb.Append(iLeft.ToString(“X2“); / 组内字节序号和残余数据初始化 iByte = 0; iLeft = 0; string sReturn=sb.ToString(); byte buf=new bytesReturn.Length/2; for(int i=0;i / 使用 8-bit 进行编码 / / 要编码的字符串 / 信息长度及编码后的字符串 static public string EncodingBit8(string s) StringBuilder sb=new String

8、Builder(); byte buf=Encoding.ASCII.GetBytes(s); sb.Append(buf.Length.ToString(“X2“); for(int i=0;i / 使用 8-bit 进行解码 / / 要解码的字符串 / 解码后的字符串 static public string DecodingBit8(string s) byte buf=new bytes.Length/2; StringBuilder sb=new StringBuilder(); for(int i=0;i / 中文短信息 UCS2 编码 / / 要编码的中文字符串 / 信息长度及编

9、码后的字符串 static public string EncodingUCS2(string s) StringBuilder sb=new StringBuilder(); byte buf=Encoding.Unicode.GetBytes(s); sb.Append(buf.Length.ToString(“X2“); for(int i=0;i / 中文短信息 UCS2 解码 / / 要解码的信息 / 解码后的中文字符串 static public string DecodingUCS2(string s) byte buf=new bytes.Length; for(int i=0;is.Length;i+=4) bufi/2=byte.Parse(s.Substring(2+i,2),System.Globalization.NumberSty les.AllowHexSpecifier); bufi/2+1=byte.Parse(s.Substring(i,2),System.Globalization.NumberSty les.AllowHexSpecifier); return Encoding.Unicode.GetString(buf);

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号