我有个解密函数是用 web里的js写的function MM_DeImages(ImageName)
{
var strSrc = ImageName;
strSrc = strSrc.substring(10);
strSrc = strSrc.substring(0,strSrc.length-5);
var strTemp = "";
var lngIndex;
for(lngIndex=1;lngIndex<=parseInt(strSrc.length/6);lngIndex+=2){
if(Math.abs(parseInt(strSrc.substring(lngIndex * 6,lngIndex * 6 + 6)) - 153874) < 32768){
strTemp = strTemp + String.fromCharCode(parseInt(strSrc.substring(lngIndex * 6,lngIndex * 6 + 6)) - 153874);
}
}
return strTemp;
}谁能给我翻译成c#呀?能力有限制,翻译不了

解决方案 »

  1.   


        private void asfd()
        { 
        
    string  strSrc = ImageName; 
    strSrc = strSrc.Substring(10);
    strSrc = strSrc.Substring(0, strSrc.Length - 5); 
    string strTemp = ""; 
    int lngIndex=1;
    for (lngIndex = 1; lngIndex <= int.Parse(strSrc.length / 6); lngIndex += 2)
    {
        if (Math.abs(int.Parse(strSrc.Substring(lngIndex * 6, lngIndex * 6 + 6)) - 153874) < 32768)
        {
            strTemp = strTemp + (char)(int.Parse(strSrc.substring(lngIndex * 6, lngIndex * 6 + 6)) - 153874);
        }

    return strTemp;     
        }
      

  2.   

    private string MM_DeImages(string ImageName) 

    string strSrc = ImageName; //此处若用.NET3.5,则可以保留var关键字,以下同
    strSrc = strSrc.SubString(10); 
    strSrc = strSrc.SubString(0, strSrc.Length - 5); 
    string strTemp = ""; 
    int lngIndex; 
    for(lngIndex = 1; lngIndex <= (int)strSrc.length/6; lngIndex+=2)

    if(Math.Abs(int.Parse(strSrc.SubString(lngIndex * 6,lngIndex * 6 + 6)) - 153874) < 32768)

    strTemp = strTemp + Char.ConvertFromUtf32(int.Parse(strSrc.SubString(lngIndex * 6,lngIndex * 6 + 6)) - 153874)).ToString(); 


    return strTemp; 

      

  3.   

        private void asfd()
        { 
        
    string  strSrc = ImageName; 
    strSrc = strSrc.Substring(10);
    strSrc = strSrc.Substring(0, strSrc.Length - 5); 
    string strTemp = ""; 
    int lngIndex=1;
    for (lngIndex = 1; lngIndex <= int.Parse(strSrc.length / 6); lngIndex += 2)
    {
        if (Math.abs(int.Parse(strSrc.Substring(lngIndex * 6, lngIndex * 6 + 6)) - 153874) < 32768)
        {  int ias=int.Parse(strSrc.substring(lngIndex * 6, lngIndex * 6 + 6) - 153874
            strTemp = strTemp + ias.Tostring();
        }

    return strTemp;     
        }
      

  4.   

    怎么都提示直对于int32太大或太小呀?
      

  5.   

    那就将上面那些代码中用到int的地方都改为long吧
      

  6.   

    貌似没用到任何高深的JS特性啊lz就那么懒 不肯自己转换一下嘛 哈哈
      

  7.   

    int64或者long 代替int32定义变量int.Parse改为Convert.ToInt64
      

  8.   

    lngIndex * 6 那这个结算的时候,是不是还的转换回去呀?他是错误 无法从“long”转换为“int”
      

  9.   

    还是提示那个错误呀?
    private string MM_DeImages(string ImageName) 
    {
        string strSrc = ImageName;
        strSrc = strSrc.Substring(10);
        strSrc = strSrc.Substring(0, strSrc.Length - 5);
        string strTemp = "";
        Int64 lngIndex = 1;
        for (lngIndex = 1; lngIndex <= Convert.ToInt64(strSrc.Length / 6); lngIndex += 2)
        {
            if (Math.Abs(Int64.Parse(strSrc.Substring((int)lngIndex * 6, (int)lngIndex * 6 + 6)) - 153874) < 32768)
            {
                strTemp = strTemp + (char)(Int64.Parse(strSrc.Substring((int)lngIndex * 6, (int)lngIndex * 6 + 6)) - 153874);
            }
        }
        return strTemp;

      

  10.   

    怎么都提示直对于int32太大或太小呀?
      

  11.   

    你这个错误比较麻烦啊,那么就先转几次(在for循环的第一句就这么写)while((long)lngIndex * (long)6 > int.MaxValue)
    {
        lngIndex -= int.MaxValue / 6;
        strSrc.Remove(0,int.MaxValue / 6);
    }
      

  12.   

    private string MM_DeImages(string ImageName) 

        string strSrc = ImageName; 
        strSrc = strSrc.Substring(10); 
        strSrc = strSrc.Substring(0, strSrc.Length - 5); 
        string strTemp = ""; 
        int lngIndex = 1; 
        for (lngIndex = 1; lngIndex <= Convert.ToInt64(strSrc.Length / 6); lngIndex += 2) 
        {
    //加入以下部分 
    while((long)lngIndex * (long)6 > int.MaxValue) 

        lngIndex -= int.MaxValue / 6; 
        strSrc.Remove(0,int.MaxValue / 6); 
    }        if (Math.Abs(Int64.Parse(strSrc.Substring(lngIndex * 6, lngIndex * 6 + 6)) - 153874) < 32768) 
            { 
                strTemp = strTemp + (char)(Int64.Parse(strSrc.Substring(lngIndex * 6, lngIndex * 6 + 6)) - 153874); 
            } 
        } 
        return strTemp; 
      

  13.   


    要转换的字符串 超出了int的范围了.......int装不了用这个类型呢  decimal