你可以这样写,也可以分割:
string s_time = "2003-3";
string[] StrTemp = s_time.Split('-');

解决方案 »

  1.   

    string str="2003-3";
    char[] Sp = new char[1];
    Sp[0]='-';
    string[] arry=str.Split(Sp);
    Response.Write(arry[0].ToString());  //"2003"
    Response.Write(arry[1].ToString());  //"3"
      

  2.   

    s_time.Remove(0,T_first.LastIndexOf("-")+1);取之后
        s_time.Substring(0,T_first.IndexOf("-"));取之前
      

  3.   

    哦,写错了
    s_time.Remove(0,s_time.LastIndexOf("-")+1);取之后
        s_time.Substring(0,s_time.IndexOf("-"));取之前
      

  4.   

    正确代码如下:
    string s_time="2003-5";//串的序是从0~Length-1,当序到了Length时已越界!//得到“2003”
    Label1.Text=s_time.Substring(0,s_time.IndexOf("-",0,s_time.Length-1)); 
                                     
    //得到“5”
    Label2.Text=s_time.Substring(s_time.IndexOf("-",0,s_time.Length-1) + 1,s_time.Length-1 - s_time.IndexOf("-",0,s_time.Length-1));仔细阅读一下系统的错误提示,会对你分析调试程序有帮助的!另外,用Substring()确实较繁,建议用Split()简洁明了得多。  ^-^