例如,字符串"afbcfbf",我要把最后的"f"去掉.如何做呢?谢谢!

解决方案 »

  1.   

    string c = "afbcfbf"
    return c.TrimEnd('f');
      

  2.   

    string a ="abcdef";
    a = a.Remove(a.Length-1);
      

  3.   

    不行哦,显示错误,如下:
    No overload for method 'Remove' takes '1' arguments
    实际代码是这样的:
    string str="";
    for (int i=0;i<this.lbDircetList.Items.Count;i++)
    {
    str = str+this.lbDircetList.Items[i].Value+",";
    }
    我要把循环后的str最后的','去掉
      

  4.   

    String s= "123abc456"; Console.WriteLine(s.Remove(s.Length-1, 1)); 
      

  5.   

    谢谢楼上的各位,最后的字符能够去掉,但我传到水晶报表里面出筛选数据时却筛选不出来.原完代码如下:
    提交:
    -----------------------------------------------------------------
    string str="";
    for (int i=0;i<this.lbDircetList.Items.Count;i++)
    {
    str = str+'"'+this.lbDircetList.Items[i].Value+'"'+",";
    }
    str = str.Remove(str.Length - 1,1);
    Page.RegisterStartupScript("","<script>window.open('rp_AttendanceTotal.aspx?departmentcode="+str.ToString()+"');</script>");
    --------------------------------------------------------------------
    水晶报表页面:
    private void ConfigurCrystalReports()
    {
    string departmentcode=Request.QueryString["departmentcode"];
    string selectionFormula = "";
    ReportDocument myReportDoc = new ReportDocument();
    string reportPath = Server.MapPath("../Reports/rp_AttendanceTotal.rpt");
    myReportDoc.Load(reportPath);
    TableLogOnInfo logonInfo = new TableLogOnInfo();
    foreach(CrystalDecisions.CrystalReports.Engine.Table tb in myReportDoc.Database.Tables)
    {
    logonInfo = tb.LogOnInfo;
    logonInfo.ConnectionInfo.ServerName = "abc";
    logonInfo.ConnectionInfo.DatabaseName = "hr";
    logonInfo.ConnectionInfo.UserID = "sa";
    logonInfo.ConnectionInfo.Password = "abc";
    tb.ApplyLogOnInfo(logonInfo);
    }
    selectionFormula = "{rp_AttendanceTotal.DepartmentCode} in ['"+departmentcode+"']";
    myReportDoc.DataDefinition.RecordSelectionFormula = selectionFormula;
    myCrystalReportViewer.ReportSource = myReportDoc;
    }
    ----------------------------------------------------------------------
    PS,如果我在lbDircetList只选中一个值提交就可以.但多选提交就能行了.没出错,但报表没数据.
      

  6.   

    OK!搞定~~
    selectionFormula = "{rp_AttendanceTotal.DepartmentCode} in ['"+departmentcode+"']";
    改为:
    selectionFormula = "{rp_AttendanceTotal.DepartmentCode} in ["+departmentcode+"]";