This is example code.
I have string with the names of planets, their order, and color, separated by spaces and NewLines.
I do not want to modify the string to change the results.
I want to create 3 Lists, Order, Name and Color from the string.
| Order | Name | Color |
|------------|------------|------------|
| First | Mercury | Gray |
| Second | Venus | Yellow |
| Third | Earth | Blue |
| Fourth | Mars | Red |
This will create a List from the string, split by NewLine.
string planets = "First Mercury Gray"
+ Environment.NewLine
+ "Second Venus Yellow"
+ Environment.NewLine
+ "Third Earth Blue"
+ Environment.NewLine
+ "Fourth Mars Red"
+ Environment.NewLine;
List<string> PlanetOrder = planets.Split(
new[] { Environment.NewLine }, StringSplitOptions.None).ToList();
List<string> PlanetName = planets.Split(
new[] { Environment.NewLine }, StringSplitOptions.None).ToList();
List<string> PlanetColor = planets.Split(
new[] { Environment.NewLine }, StringSplitOptions.None).ToList();
But within each line how can I also Split by space and choose word [1]Order, [2]Name, [3]Color?
planets.Split(' ')[2]; //Name