Splitting a string and ignoring the delimiter inside quotes

前端 未结 4 1380
轻奢々
轻奢々 2021-02-19 10:48

I am using .NET\'s String.Split method to break up a string using commas, but I want to ignore strings enclosed in double quotes for the string. I have read that a

For

4条回答
  •  伪装坚强ぢ
    2021-02-19 11:25

    if using c#, you can use

            string searchQuery = "Fruit,10,\"Bananas, Oranges, Grapes\"";
            List list1 = Regex.Matches(searchQuery, @"(?\w+)|\""(?[\w\s,]*)""").Cast().Select(m => m.Groups["match"].Value).ToList();
            foreach(var v in list1)
            Console.WriteLine(v);
    

    Output :

    Fruit

    10

    Bananas, Oranges, Grapes

提交回复
热议问题