日期:2014-05-18  浏览次数:20578 次

进来帮忙解释段代码!!谢谢啊!
public static string ConvertHexToString(string source)
  {
  byte[] oribyte = new byte[source.Length/2];
  for(int i=0;i<source.Length;i+=2)
  {
  string str = Convert.ToInt32(source.Substring(i,2),16).ToString();
  oribyte[i/2] = Convert.ToByte(source.Substring(i,2),16);
  }
  return System.Text.Encoding.Default.GetString(oribyte);
  }

这段代码,关键的地方,后面帮注上注释。。。谢谢。。


------解决方案--------------------
C# code

 protected void GridViewRelation_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        CostManagement Cost = new CostManagement();
        if (e.CommandName.ToUpper() == "HISTORYRECORD")
        {
             int i = Convert.ToInt32(e.CommandArgument);
             string cardId = GridViewRelation.Rows[i].Cells[5].Text;
             string carno = GridViewRelation.Rows[i].Cells[4].Text;
            string url = "FrmAtrriHistory.aspx?cardId=" + cardId + "&carno=" + carno;
            string ClientScript = "window.showModalDialog('" + url + "','history','dialogWidth:800px;dialogHeight:600px;dialogLeft:200px;dialogTop:200px;center:yes; help:yes;resizable:yes;status:yes')";
            Page.RegisterStartupScript("pringGP", "<script>" + ClientScript + "</script>");
        }
    }
 CostManagement();
        if (e.CommandName.ToUpper() == "HISTORYRECORD")
        {
             int i = Convert.ToInt32(e.CommandArgument);
             string cardId = GridViewRelation.Rows[i].Cells[5].Text;
             string carno = GridViewRelation.Rows[i].Cells[4].Text;
            string url = "FrmAtrriHistory.aspx?cardId=" + cardId + "&carno=" + carno;
            string ClientScript = "window.showModalDialog('" + url + "','history','dialogWidth:800px;dialogHeight:600px;dialogLeft:200px;dialogTop:200px;center:yes; help:yes;resizable:yes;status:yes')";
            Page.RegisterStartupScript("pringGP", "<script>" + ClientScript + "</script>");
        }
    }

------解决方案--------------------
举个例子来说:
我爱你
使用系统默认的编码格式(936)编码后的16进制串为:
CED2B0AEC4E3
用这个字符串(CED2B0AEC4E3)调用你的函数,将返回“我爱你”这个字符。

------解决方案--------------------
学习。
------解决方案--------------------
study..