功能需求如下:如字符串1为:  csdn.net/userprofile/Jack.aspx  对应: csdn.net/index.aspx?type=userprofile&userID=Jack
字符串1为:  csdn.net/login.aspx  对应: csdn.net/index.aspx?type=login本意是想这样: 
{0}/{1}/{2}.aspx --> {0}/index.aspx?type={1}&userID={2}
{0}/{1}.aspx --> {0}/index.aspx?type={1}可以怎么实现呢? 

解决方案 »

  1.   

    URL传值 
    可以可以的去添加??
    没用吧~~
      

  2.   

    用string.format()这个方法可以实现你想要的效果
      

  3.   

    string resultString = null;
    try {
    resultString = Regex.Replace(subjectString, "(.*)/(.*)/(.*).aspx", @"\1/index.aspx?type=\2&userID=\3");
    } catch (ArgumentException ex) {
    // Syntax error in the regular expression
    }
      

  4.   

    string resultString = null;
    try {
    resultString = Regex.Replace(subjectString, "(.*)/(.*)/(.*).aspx", @"\1/index.aspx?type=\2&userID=\3");
    } catch (ArgumentException ex) {
    // Syntax error in the regular expression
    }
      

  5.   

    见鬼string resultString = "csdn.net/userprofile/Jack.aspx";
    try {
    resultString = Regex.Replace(subjectString, "(.*)/(.*)/(.*).aspx", @"\1/index.aspx?type=\2&userID=\3");
    } catch (ArgumentException ex) {
    // Syntax error in the regular expression
    }
      

  6.   


     string strContent = "csdn.net/login.aspx";
                Regex re = new Regex(@"(?<info>[^/]*/)((?<type>[^/]*)/)*(?<value>[^\.]*)");
                string strInfo = ""; string strType = ""; string strValue = "";
                if (re.IsMatch(strContent))
                {
                    Match m = re.Match(strContent);
                    strInfo = m.Groups["info"].Value.Trim();
                    strValue = m.Groups["value"].Value.Trim();
                    if (m.Groups["type"] != null)
                    {
                        strType = m.Groups["type"].Value.Trim();
                    }
                }
                strContent = strInfo + "index.aspx?" + (strType == "" ? "type=" + strValue : "type=" + strType + "&userID=" + strValue);