Rich Newman

ColonDelimitedMovieFinder Class – .Net

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace MovieFinderTestSpring.Net
{
    public class ColonDelimitedMovieFinder : IMovieFinder
    {
        #region IMovieFinder Members

        public List<Movie> FindAll()
        {
            List<Movie> movieList = new List<Movie>();
            FileInfo file = new FileInfo(".\\Movies.txt");
            if (file.Exists)
            {
                StreamReader streamReader = new StreamReader(file.FullName);
                {
                    try
                    {
                        while (!streamReader.EndOfStream)
                        {
                            string line = streamReader.ReadLine();
                            //string[] movieData = line.Split(new char[] {':'});
                            string title = line.Remove(line.IndexOf(":"));
                            string director = line.Substring(line.IndexOf(":") + 1);
                            Movie movie = new Movie(title, director);
                            movieList.Add(movie);
                        }
                    }
                    finally { streamReader.Close(); }
                }
            }
            return movieList;
        }

        #endregion
    }
}
 

Leave a Comment »

No comments yet.

RSS feed for comments on this post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: