function jinzhih_G1($zifu){
$shu= "";
    for ($i=0;$i<=strlen($zifu)-1;$i++){
$linshi = substr($zifu,$i,1);
if (ord($linshi)<=57){
$shu=bcadd($shu,bcmul((ord($linshi)-48),bcpow($jinzhi,strlen($zifu)-$i-1)));
        }else{
            $shu=bcadd($shu,bcmul((ord($linshi)-55),bcpow($jinzhi,strlen($zifu)-$i-1)));
}                  
     }
 return $shu;
}
哪位大哥帮我把这段PHP代码转换成C#代码!
感激不尽

解决方案 »

  1.   


    private String  jinzhih_G1(zifu){
        string shu= "";
        string linshi="";
        string jinzhi="";
        for (int i=0;i<=strlen(zifu)-1;i++){
            linshi = substr(zifu,i,1);
            if (ord(linshi)<=57){
                shu=bcadd(shu,bcmul((ord(linshi)-48),bcpow(jinzhi,strlen(zifu)-i-1)));
            }else{
                shu=bcadd(shu,bcmul((ord(linshi)-55),bcpow(jinzhi,strlen(zifu)-i-1)));
            }                  
         }
         return shu;
    }
      

  2.   

    晓静姐,这个一眼就能看出来不对!strlen、ord、bcadd、bcmul......等等这些都是PHP特有的函数,在c#里是没有的!要是有的话我也会的!
    不过还是谢谢你的回复!
      

  3.   

    string   shu=   " "; 
    shu.Length()
    shu.Substring()
    Chr()
    Ord()
    bcadd 没有
    public string function bcadd(string left_operand, string right_operand, string scale)
    {
       int t = Convert.ToSingle(left_operand) + Convert.ToSingle(string right_operand);
       result=t.ToString("f"+scale);
    }
      

  4.   

    bcadd, bcmul, bcpow这三个貌似C#里面没有,所以干脆都自定义函数实现。有点错误,思路大概是思路,你要搞清楚$shu是什么类型的数据,$jinzhi你在哪里定义的~~~
    public string jinzhih_G1(string zifun)
        {
            string shu= "";
            string jinzhi = ""; //不知道这个参数干吗用的
            System.Text.ASCIIEncoding ascii = new System.Text.ASCIIEncoding();
            for (int i = 0; i < zifun.Length; i++)
            {
                string linshi = zifun.Substring(i, 1);
                int a = (int)ascii.GetBytes(linshi)[0];
                if (a <= 57)
                {
                    shu += this.myfunc(shu, this.myfunc((a - 48), this.myfunc(jinzhi, zifun.Length - i - 1, 0, 3), 0, 2), 0, 1);
                }
                else
                {
                    shu += this.myfunc(shu, this.myfunc((a - 55), this.myfunc(jinzhi, zifun.Length - i - 1, 0, 3), 0, 2), 0, 1);
                }
            }
            return shu;
        }    /// <summary>
        /// C#模拟实现bcadd、bcmul和bcpow这三个PHP函数.
        /// </summary>
        /// <res>
        /// 示例:  
        /// string result = ExecuteNonQuery("1.2345", "5", 3, 2);
        /// </res>
        /// <param name="x">对象x</param>
        /// <param name="y">对象y</param>
        /// <param name="z">小数点后位数</param>
        /// <param name="method">计算方法</param>
        /// <returns>返回字符串</returns>
        private string myfunc(object x, object y, int z, int method)
        {
            double a = Convert.ToDouble(x);
            double b = Convert.ToDouble(y);
            double c = 0;
            //通过switch实现bcadd、bcmul和bcpow这三个PHP函数
            switch (method)
            {
                case 1: c = a+b; break;
                case 2: c = a * b; break;
                case 3: c = Math.Pow(a, b); break;        }
            double d = Math.Truncate(c);
            string e = Convert.ToString(d) + Convert.ToString(c - d).Substring(1, z+1);
            return Convert.ToString(e);
        }