Delete everything after part of a string

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

    Perhaps thats what you are looking for:

    String str="Stack Overflow - A place to ask stuff";
    
    String newStr = str.substring(0, str.indexOf("-"));
    

提交回复
热议问题