Delete everything after part of a string

后端 未结 10 2178
时光取名叫无心
时光取名叫无心 2020-12-03 09:25

I have a string that is built out of three parts. The word I want the string to be (changes), a seperating part (doesn\'t change) and the last part which changes. I want to

10条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 10:12

    String line = "deltaasm:/u01/app/oracle/product/11.2.0/dbhome_1:N        # line addred by agent";
    
        String rep = "deltaasm:";
        String after = "";
    
        String pre = ":N";
        String aft = "";
        String result = line.replaceAll(rep, after);
        String finalresult = result.replaceAll(pre, aft);
        System.out.println("Result***************" + finalresult);
    
        String str = "deltaasm:/u01/app/oracle/product/11.2.0/dbhome_1:N        # line addred by agent";
    
        String newStr = str.substring(0, str.indexOf("#"));
        System.out.println("======" + newStr);
    

提交回复
热议问题