Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Collections.ObjectModel;
- using System.IO;
- namespace _1DV402.S3.L1
- {
- enum RecipeReadStatus {Indefinite, New, Ingredient, Direction }
- class RecipeRepository
- {
- private string _path;
- public string Path
- {
- get { return _path; }
- set
- {
- if (String.IsNullOrWhiteSpace(value))
- {
- Console.WriteLine("Strängen är tom eller innehåller mellanslag!");
- }
- _path = value;
- }
- }
- public RecipeRepository(string path) //Path får sitt värde i konstruktorn, skickas från LoadRecipes.
- {
- Path = path;
- }
- public IList<Recipe> Load()
- {
- List<string> LoadRecipe = new List<string>();
- using(StreamReader reader = new StreamReader (this.Path))
- {
- //Läs in ] då vet du att du kommer vara inne på namnet.
- //Gör en sträng av det, sen nästa gång ] kommer du vara vid ingredienserna
- //och vid varje ; sätter du ett space istället och vid varje whitespace(alltså ny rad)
- //så vet du att det kommer en ny ingrediens.
- //Använd arraynamn.Length för att kolla om den har tre delar.
- String textLine; //Används för att läsa filen.
- while ((textLine = reader.ReadLine()) != null) //Läser filen rad för rad så länge null inte returneras.
- {
- textLine = reader.ReadLine(); //Läser en rad.
- string[] ingredients = textLine.Split(new string[] { ";", ";;" }, StringSplitOptions.RemoveEmptyEntries); //Delar upp i tre strängar.
- }
- }
- return //En instans av nån instans bla bla bla
- }
- }
- }
Add Comment
Please, Sign In to add comment