比如
abcd_ef.txt
如何找到“_”之前的子串,“_”和“.”中间的子串?

解决方案 »

  1.   

    if (abcd_ef.txt.indexof("_")>0)
    {
    存在
    }
    if(abcd_ef.txt.indexof(".")>0)
    {
    存在
    }
      

  2.   

    刚在没有看清楚
    在"存在"处  abcd_ef.txt .substring()
      

  3.   

    abcd_ef.txt.indexof("_")返回“_”在abcd_ef.txt的位置
      

  4.   

    int index1 = "abcd_ef.txt".indexof('_');
    int index2 = "abcd_ef.txt".indexof('.');
    string str1 = "abcd_ef.txt".substring(0,index1);
    string str2 = "abcd_ef.txt".substring(index1+1,index2-index1>0?index2-index1:0);
      

  5.   

    找出_之前的子串:
    string str="abcd_ef.txt";
    str=str.substring(0,str.lastindexof('_'));找出_和.中间的子串:
    string str="abcd_ef.txt";
    str=str.substring(str.lastindexof('_')+1,strlastindexof('.'));
      

  6.   

    string str = "abcd_ef.txt";
                int indexof_ = str.IndexOf('_');
                string substr1 = str.Substring(0, indexof_);
                string substr2=str.Substring(indexof_+1,str.IndexOf('.')-(indexof_+1));