Delete everything after part of a string

后端 未结 10 2187
时光取名叫无心
时光取名叫无心 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:05

    you can my utils method this action..

    public static String makeTwoPart(String data, String cutAfterThisWord){
        String result = "";
    
        String val1 = data.substring(0, data.indexOf(cutAfterThisWord));
    
        String va12 = data.substring(val1.length(), data.length());
    
        String secondWord = va12.replace(cutAfterThisWord, "");
    
        Log.d("VAL_2", secondWord);
    
        String firstWord = data.replace(secondWord, "");
    
        Log.d("VAL_1", firstWord);
    
        result = firstWord + "\n" + secondWord;
    
    
        return result;
    }`
    

提交回复
热议问题