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

后端 未结 6 1587
清酒与你
清酒与你 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:47

    public class MyTestSecond { 
    public static void main(String...args){
    
        String a = "hey 110 say \"I am not very good at Java\"";
        // Method 1
        if(a.contains("\""))
            System.out.println(a.substring(a.indexOf("\""),a.lastIndexOf("\"")+1));
        //Method 2
        String[] array = a.split(" ");
        for(int i=0;i

    }

提交回复
热议问题