How do I get what's inbetween “ ” in a user inputted String? Java

后端 未结 6 1578
清酒与你
清酒与你 2021-01-26 13:58

I\'d like to retrieve whatever is in quotes that someone enters as a string, i\'m assuming it\'s substring that I need but i\'m not sure how.

When the user inputs a stri

6条回答
  •  情歌与酒
    2021-01-26 14:52

    public String getNextQuote(int index, String sentence){
     return sentence.substring(sentence.indexOf("\"", index + 1), sentence.indexOf("\"", index + 2));
    }
    

    usage: call the method with an index as parameter. This index resembles the index of the last " that you've encountered.

    Afterwards, it will return everything between the next two quotes.

提交回复
热议问题