c#短信网关中关于短信内容编码的转换
无论在cmpp或sgip中,都会遇到短信编码格式转换的问题。
因为现在短信编码常用的格式有三种:0:ASCII串,8:UCS2编码,15:含GB汉字。在发送或接收短信时,都会用到相应的编码转换。如以下代码:
public static String Decode(Byte[] buf, int StartIndex, int Length, CODING Coding)
{
String str = String.Empty;
if (Coding == CODING.ASCII)
str = System.Text.Encoding.ASCII.GetString(buf, StartIndex, Length);
else if (Coding == CODING.UCS2)
str = System.Text.Encoding.BigEndianUnicode.GetString(buf, 0, Length);
else if (Coding == CODING.GBK)
str = System.Text.UnicodeEncoding.GetEncoding("gb2312").GetString(buf, StartIndex, Length);
return str;
}
public static Byte[] Encode(String str, CODING coding)
{
Byte[] buf = null;
if (str == null)
return buf;
if (coding == CODING.ASCII)
buf = System.Text.Encoding.ASCII.GetBytes(str);
else if (coding == CODING.UCS2)
buf = System.Text.Encoding.BigEndianUnicode.GetBytes(str);
else if (coding == CODING.GBK)
buf = System.Text.UnicodeEncoding.GetEncoding("gb2312").GetBytes(str);
return buf;
}
public static UInt32 CountLength(String str, CODING coding)
{
Byte[] buf = Encode(str, coding);
if (buf != null)
return (UInt32)buf.Length;
else
return 0;
}
在处理接收DELIVER时,也可以这样写
if (Msg_Fmt != 8)
{
if (Msg_Fmt != 15)
{
this.Msg_Content = System.Text.Encoding.ASCII.GetString(buffer, iPos, (int)this.Msg_Length);
}
else
{
this.Msg_Content = Syst
相关文档:
问:C# 加密后为何有两种结果的字符串?
比如 cftea 的 MD5 加密后:
有的人的结果是:c2e1861ca90e67ce1f9a62f9c27d8bdc
有的人的结果是:wuGGHKkOZ84fmmL5wn2L3A
答:这是对字节的两种不同表示结果。
第一种是用十六进制表示的(FormsAuthentication.HashPasswordForStoringInConfigFile 就是这种,只是是大写的), ......
原文链接:http://www.cnblogs.com/ding0910/archive/2007/07/12/815407.html
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using BX.Interface;
......
<@Aattention Content="本Blog原创文章,转载或引用请注明转载"
from="Robby.cnblogs.com"@>
由于自己的搜索引擎中做到了这一块内容,所以今天说说如何抓取网页数据、分析并且去除Html标签,给大家提供一个参考。我的平台是Visual
Studio2005,C#。
& ......
直接封装成一个类的,用起来还挺方便的
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text ......
C#:
创建:
HttpCookie cookie = new HttpCookie("regID");
cookie .Value = username;
cookie .Expires = DateTime.Now.AddDays(1);
& ......