类似a_b_c_d_e_d_的字符串我要取得a_b_c_d_e_就是去掉最后的字母和_ 望指点一下,
_之间的字符数是不固定的

解决方案 »

  1.   

    SUBSTR(字符,0,LENGTH(字符)-2)
      

  2.   

    string aa;
    aa = aa.Replace("_", "");
    再去掉最后的字母
      

  3.   

    得到字符的长度
                string str = "sddsfd";
                str.Substring(0,str.Length-2)
      

  4.   

    string str = "a_b_c_d_e_d_";
    string temp = str.Substring(0, str.LastIndexOf("_"));
    str = temp.Substring(0, temp.LastIndexOf("_") + 1);
      

  5.   

    string str1 = "a_b_c_d_e_f_g_h_";
    Label1.Text = str1.Substring(0,(str1.Length-2));
    这样就行.如果还要去掉所有的 _ .那就 Replace("_", "") 一样就行了.
      

  6.   

    string a="a_b_c_d_e_d_";
    a=Regex.Replace(a,"(?<=_)[^_]+_$","");
      

  7.   

    lovefootball的方法可以,之前的做法是用string.split形成数组再连接,感觉太麻烦了