Regex: C# extract text within double quotes

后端 未结 7 1062
悲哀的现实
悲哀的现实 2020-11-27 17:03

I want to extract only those words within double quotes. So, if the content is:

Would \"you\" like to have responses to your \"questions\" sent to you

7条回答
  •  情书的邮戳
    2020-11-27 17:27

    I like the regex solutions. You could also think of something like this

    string str = "Would \"you\" like to have responses to your \"questions\" sent to you via email?";
    var stringArray = str.Split('"');
    

    Then take the odd elements from the array. If you use linq, you can do it like this:

    var stringArray = str.Split('"').Where((item, index) => index % 2 != 0);
    

提交回复
热议问题