Advertisement
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.Reflection;
- using System.IO;
- namespace ReadText
- {
- class Program
- {
- static void Main(string[] args)
- {
- var cheese = GetTextResource("TextFile1.txt");
- Console.WriteLine(cheese.Count(x => x == '{'));
- Console.WriteLine(cheese.Count(x => x == '}'));
- Console.ReadLine();
- }
- public static string GetTextResource(string name)
- {
- Assembly assembly = Assembly.GetExecutingAssembly();
- string contents = string.Empty;
- try
- {
- Stream strm = assembly.GetManifestResourceStream(assembly.GetName().Name.ToString() + "." + name);
- StreamReader reader = new StreamReader(strm);
- contents += reader.ReadToEnd();
- reader.Close();
- return contents;
- }
- catch (IOException ex)
- {
- Console.WriteLine(ex.Message);
- return string.Empty;
- }
- catch (ArgumentNullException ex)
- {
- Console.WriteLine(ex.Message);
- return string.Empty;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement