例如:把字符串01/05/2009 - 01/11/2009改成2009/01/05- 2009/01/11 
把年放在前面

解决方案 »

  1.   

    string str = "01/05/2009 - 01/11/2009";
            string patternstr = @"(\d+)/(\d+)/(\d+)";
            str = Regex.Replace(str, patternstr, "$3/$2/$1");
            Response.Write(str);
      

  2.   

    string from = "01/05/2009 - 01/11/2009"; 
                    string fromnew = from.Substring(6, 4) + '/' + from.Substring(3, 2) + '/' + from.Substring(0, 2); 
                    string to = from.Substring(13, 10); 
                    string tonew = to.Substring(6, 4) + '/' + to.Substring(3, 2) + '/' + to.Substring(0, 2); 
                    list[i].InnerText = fromnew + "-" + tonew; 
      

  3.   

    string from = "01/05/2009 - 01/11/2009"; 
                    string fromnew = from.Substring(6, 4) + '/' + from.Substring(3, 2) + '/' + from.Substring(0, 2); 
                    string to = from.Substring(13, 10); 
                    string tonew = to.Substring(6, 4) + '/' + to.Substring(3, 2) + '/' + to.Substring(0, 2); 
    string newString  = fromnew + "-"+tonew;
      

  4.   

     string from = "01/05/2009 - 01/11/2009";
                string fromnew = from.Substring(6, 4) + '/' + from.Substring(0, 5) ;
                string to = from.Substring(13, 10);
                string tonew = to.Substring(6, 4) + '/' + to.Substring(0, 5) ;
                string newString = fromnew + "-" + tonew;
                Console.WriteLine(newString);