110,533
社区成员
发帖
与我相关
我的任务
分享
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
string a(string value)
{
return value.Replace(".html", "").Replace("section-", "section.aspx?").Replace("-", "&").Replace("_", "=");
}
string a(string value)
{
string result = Regex.Replace(value, @"\.aspx\?|[=&]", delegate(Match m) { return m.Length == 1 ? "_" : "-"; });
}
string test = "section.aspx?sid=9&t=0&p=1";
string result = Regex.Replace(test, @"\.aspx\?|[=&]", delegate(Match m) { return m.Length == 1 ? "_" : "-"; });