Delete everything after part of a string

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

    For example, you could do:

    String result = input.split("-")[0];
    

    or

    String result = input.substring(0, input.indexOf("-"));
    

    (and add relevant error handling)

提交回复
热议问题