'How split this specific string into array [duplicate]

How can i split this specific string with spaces into array?
MyDatabase C:\MyDatabase\Backup "C:\Program Files\MySQL\MySQL Server 8.0\bin"
I want to have array like this: \

[MyDatabase], [C:\MyDatabase\Backup], ["C:\Program Files\MySQL\MySQL Server 8.0\bin"]


I can't match any specific sperator for .Split() function



Solution 1:[1]

Try this

var path = @"MyDatabase C:\MyDatabase\Backup ""C:\Program Files\MySQL\MySQL Server 8.0\bin""";
            var pattern = @"(?<FirstWord>\w+)\s(?<Path1>.*)\s(?<Path2>\"".*\"")";
            Debug.WriteLine(path);
            Regex rgx = new Regex(pattern);
            Match match = rgx.Match(path);
            if (match.Success)
                ShowMatches(rgx, match);

private static void ShowMatches(Regex r, Match m)
        {
            string[] names = r.GetGroupNames();
            Debug.WriteLine("Named Groups:");
            foreach (var name in names)
            {
                Group grp = m.Groups[name];
                Debug.WriteLine("   {0}: '{1}'", name, grp.Value);
            }
        }

Solution 2:[2]

 var s=@"mydbbb D:\\mssql ""C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\""";

 Console.WriteLine(s.Split(' ')[0]);
 Console.WriteLine(s.Split(' ')[1]);

 int i = s.IndexOf(' ');
 i = s.IndexOf(' ', i + 1);
 Console.WriteLine(s.Substring(i));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pe0067 PEOR
Solution 2