Function DeCodeAnsi(s)
    Dim i, sTmp, sResult, sTmp1
    sResult = ""
    For i=1 To Len(s)
        If Mid(s,i,1)="%" Then
            sTmp = "&H" & Mid(s,i+1,2)
            If isNumeric(sTmp) Then
                If CInt(sTmp)=0 Then
                    i = i + 2
                ElseIf CInt(sTmp)>0 And CInt(sTmp)<128 Then
                    sResult = sResult & Chr(sTmp)
                    i = i + 2
                Else
                    If Mid(s,i+3,1)="%" Then
                        sTmp1 = "&H" & Mid(s,i+4,2)
                        If isNumeric(sTmp1) Then
                            sResult = sResult & Chr(CInt(sTmp)*16*16 + CInt(sTmp1))
                            i = i + 5
                        End If
                    Else
                        sResult = sResult & Chr(sTmp)
                        i = i + 2
                    End If
                End If
            Else
                sResult = sResult & Mid(s,i,1)
            End If
        Else
            sResult = sResult & Mid(s,i,1)
        End If
    Next
    DeCodeAnsi = sResult
End Function

解决方案 »

  1.   

    转化成阿斯码的函数???.net里面就是一行代码的事
    StringToWideChar 将ANSI字符串转换为UNICODE字符串 
    WideCharLenToString 函数 将ANSI字符串转换为UNICODE字符串 
    WideCharLenToStrWar 函数 将UNICODE字符串转换为ANSI字符串变量 
    WideCharToString 函数 将UNICODE字符串转换为ANSI字符串 
    WideCharToStrVar 函数 将UNICODE字符串转换为ANSI字符串变量
      

  2.   

    只有If ... Then ... Else ... End If的东西要转换都有难度?就全部改成if (...) {...} else {...}咯。这段代码Dim的都是无类型的,应该是ASP代码吧?那么搂主应该是想知道CInt、Chr、Mid、Len、IsNumeric在c#中用什么替代吧?CInt(x)直接用((int)x)就好了,当然最好放到try里面。Chr没有直接对应的。string类型的话先要通过str[0]的方式取得char类型。如果是char类型的话,它既代表一个ascii字符,而它本身也是一个数值就是该ascii字符的ascii码值。所以Chr的话其实就是直接把该数值传递给char类型就行了,然后该char类型可以直接和string进行拼接或者别的。Mid(str, x, y)改为str.SubString(m, n)就行了。注意m和n不是直接等于x和y,因为VB里面第一个字符下标为1,C#里面第一个字符下标为0。Len(str)就是str.Length。IsNumeric(str)好像没有等价方法,只能用try嵌套Convert来尝试一下。原VB的IsNumeric是比较强大的,只要能够识别为数字的字符串都返回true,例如"01.2345e-6",所以你考虑一下是不是自己编写一个IsNumeric吧。
      

  3.   

    TO cat_hsfz:是的,因为我之前是写ASP的,现在正在学习ASP.Net,有好多函数都不了解,所以昨天晚上自己尝试转成C#的时候失败了,不知道ASP中的一些函数改成C#的应该怎么写。C#中没有像javascript一样的isNaN这个函数吗?TO MyLf(不睡觉的鱼):这不正在学的嘛。:P
    感谢所有回复的朋友。
      

  4.   

    到这个网站去转换:
    http://www.developerfusion.co.uk/utilities/convertvbtocsharp.aspx
      

  5.   

    TO winner2050(winner) :你给的那几个函数怎么调用的啊?
      

  6.   

    IsNumeric 有等价的,MS怎回让旁落如此简单的方法实现
    是 Char.IsNumeric
      

  7.   

    public string DeCodeAnsi(string s)
    {
    string returnValue;
    int i;
    string sTmp;
    string sResult;
    string sTmp1;
    sResult = "";
    for (i = 0; i < s.Length; i++)
    {
    if (s.Substring(i,1) == "%")
    {
    sTmp = "&H" + s.Substring(i+1,2);
    if (Information.IsNumeric(sTmp))
    {
    if (System.Convert.ToInt32(sTmp) == 0)
    {
    i = i + 2;
    }
    else if (System.Convert.ToInt32(sTmp) > 0 && System.Convert.ToInt32(sTmp) < 128)
    {
    sResult = sResult + Strings.Chr(System.Convert.ToInt32(sTmp));
    i = i + 2;
    }
    else
    {
    if (s.Substring(i+3,1) == "%")
    {
    sTmp1 = "&H" +s.Substring(i+4,2);
    if (Information.IsNumeric(sTmp1))
    {
    sResult = sResult + Strings.Chr(System.Convert.ToInt32(sTmp) * 16 * 16 + System.Convert.ToInt32(sTmp1));
    i = i + 5;
    }
    }
    else
    {
    sResult = sResult + Strings.Chr(System.Convert.ToInt32(sTmp));
    i = i + 2;
    }
    }
    }
    else
    {
    sResult = sResult + s.Substring(i,1);
    }
    }
    else
    {
    sResult = sResult + s.Substring(i,1);
    }
    }
    returnValue = sResult;
    return returnValue;
    }
      

  8.   

    ASP中也没有isNaN这个函数啊。C#里面都没有NaN这个常量,当然也没有isNaN啦。这段代码在VB.NET应该是能够运行的,然后你学习C#语法之后再尝试转为C#吧。如果你太过习惯ASP的做法,那就用VB.NET吧。客户端还是用Javascript就可以了。