易截截图软件、单文件、免安装、纯绿色、仅160KB

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# 加密-Rijndael

Rijndael
属对称加密,对称加密在加密和解密时都使用相同的密钥。2000 年 10 月,NIST 选择 Rijndael(发音为 "Rhine dale")作为 AES 算法,用以取代 DES。
Rijndael 的名称空间是:
System.Security.Cryptography
byte[] plaintextBuffer = System.Text.Encoding.UTF8.GetBytes("明文");

// ......

C# 获取 SQL服务器列表

#region   得到所有本地网络中可使用的SQL服务器列表  
  ///   <summary>  
  ///   得到所有本地网络中可使用的SQL服务器列表  
  ///   </summary>  
  ///   <param   name="p_strServerList">服务器列表</param& ......

C#调用C DLL

在合作开发时,C#时常需要调用C++DLL,当传递参数时时常遇到问题,尤其是传递和返回字符串是,现总结一下,分享给大家:
VC++中主要字符串类型为:LPSTR,LPCSTR, LPCTSTR, string, CString, LPCWSTR, LPWSTR等
但转为C#类型却不完全相同。
主要有如下几种转换:
将string转为IntPtr:IntPtr System.Runtime.InteropServ ......

asp.net c# js服务器端常用

using System;
using System.Web;
namespace pub.mo
{
public class js
{
private js() { }
private static string scr_j1 = "<mce:script type=\"text/javascript\"><!--
";
private static string scr_j2 = "
// --></mce:script>";
/// <summa ......

asp.net c# request常用

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
namespace pub.mo
{
public class request
{
private request() { }
/// <summary>
/// 获取session
/// </summary>
/// <param name="_session_name" ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号