其实是用来做伪静态的。求一段代码,或者算法
要根据相应的html文件名字符串分析出对应带参数的aspx文件的路径来。section-sid_9-t_0-p_1.html 对应 section.aspx?sid=9&t=0&p=1
section-nid_3-t_1.html 对应 section.aspx?nid=3&t=1
section-cid_1-p_3.html 对应 secion.aspx?cid=1&p=3
section-p_16.html 对应 section.aspx?p=16
seciton-cid_1.html 对应 secion.aspx?cid=1要是有好的伪静态文件命名格式,能解决问题,也可以。

解决方案 »

  1.   

    dim str as string="section-sid_9-t_0-p_1.html"
    dim i as integer=instr(str,"-")
    str=mid(str,1,i-1) & ".aspx?" & mid(str,i+1)
    i=instr(str,"_")
    str=mid(str,1,i-1) & "=" & mid(str,i+1)
    ...
    ...
    可以吗?
    主要是能找到规则吧
      

  2.   


    这个代码是可以,不过我的意思是通过一种方法能适应上面几种html文件名的格式。
    不是只针对某一种格式单独写一段代码比如我有个方法 string a(string value);
    当我调用 a(静态文件名)的时候就能返回相应的动态路径来。
      

  3.   


    string test = "section.aspx?sid=9&t=0&p=1";
    string result = Regex.Replace(test, @"\.aspx\?|[=&]", delegate(Match m) { return m.Length == 1 ? "_" : "-"; });
      

  4.   

    string a(string value)
    {
        string result = Regex.Replace(value, @"\.aspx\?|[=&]", delegate(Match m) { return m.Length == 1 ? "_" : "-"; });
    }
      

  5.   


    大哥,你这个很nb的,帮我写一个反算的,根据html格式算aspx格式的。
      

  6.   

    我个人建议在此处不用正则表达式,因为正则表达式比字符串处理(remove,replace等)的速度要慢很多。
    很明显,你这是URL重写,几乎每个访问的页面都会用到这个函数,那么性能方面就很重要,宁可写得复杂一点,但是性能要好,不能求简单用正则表达式。
      

  7.   

    string a(string value)
    {
        return value.Replace(".html", "").Replace("section-", "section.aspx?").Replace("-", "&").Replace("_", "=");
    }
      

  8.   


    怎么不对你贴出例子。
    static void Main(string[] args)
    {
        string[] test = new string[] { "section.aspx?sid=9&t=0&p=1", "section.aspx?nid=3&t=1", "section.aspx?cid=1&p=3", "section.aspx?p=16", "section.aspx?cid=1" };
        foreach (string s in test)
        {
            Console.WriteLine(a(s) + " 对应 " + s);
        }
        Console.ReadKey();
    }static string a(string value)
    {
        return Regex.Replace(value, @"\.aspx\?|[=&]", delegate(Match m) { return m.Length == 1 ? "_" : "-"; })+".html";
    }
    结果:
    section-sid_9_t_0_p_1.html 对应 section.aspx?sid=9&t=0&p=1
    section-nid_3_t_1.html 对应 section.aspx?nid=3&t=1
    section-cid_1_p_3.html 对应 section.aspx?cid=1&p=3
    section-p_16.html 对应 section.aspx?p=16
    section-cid_1.html 对应 section.aspx?cid=1你提问的自己要吧问题描述清楚。而且。你例子是错的。section,有些笔误的,这是笔误还是既定情况?允许secion的?你要说明白。否则写再多都是白写。
      

  9.   


            public static String ChangeFormat(String str)
            {
                Int32 i = str.IndexOf('-');
                if (i < 0)
                {
                    return str.Substring(0, str.IndexOf('.')) + ".aspx";
                }
                else
                {
                    String start = str.Substring(0, i) + ".aspx?";
                    String temp = str.Substring(i + 1, str.IndexOf('.') - i - 1);
                    return start + temp.Replace('_', '=').Replace('-','&');
                }        }