Advertisement
Guest User

TextManip

a guest
Apr 24th, 2014
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7.  
  8. namespace ConsoleApplication8
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string Filename = "text.txt";
  15.             int lastStr = 0;
  16.             try
  17.             {
  18.                 if (File.Exists(Filename))
  19.                 {
  20.                     StreamReader sr = new StreamReader(Filename);
  21.                     string line;
  22.                     int lastLine = 0;
  23.                     // string resultStr = "";
  24.                     while ((line = sr.ReadLine()) != null)
  25.                     {
  26.                         if (line == "")
  27.                             continue;
  28.                         line = line.Replace(" ", "");
  29.                         if (Char.IsDigit(line[0]))
  30.                         {
  31.                            
  32.                             if (line[1] == '.')
  33.                         lastLine = line[0] - '0';
  34.                             else if (Char.IsDigit(line[1]))
  35.                             {
  36.                                 if (line[2] == '.')
  37.                                 {
  38.                                     lastLine = Convert.ToInt16(string.Concat(line[0],line[1]));
  39.                                 }
  40.                             }
  41.                                
  42.                         }
  43.  
  44.                     }
  45.                     lastStr = lastLine;
  46.                     sr.Close();
  47.                 }
  48.             }
  49.             catch (Exception e)
  50.             {
  51.                 Console.WriteLine("Exception type is {0} \n", e.GetType());
  52.             }
  53.  
  54.             try
  55.             {
  56.                 StreamWriter sw = new StreamWriter(Filename, true);
  57.                 int j = 1;
  58.                 for (int i = lastStr + 1; i < lastStr + 1+10; i++, j++)
  59.                 {
  60.                     sw.WriteLine(i.ToString() + ". " + "Some text " + j);
  61.                 }
  62.  
  63.                 sw.Close();
  64.             }
  65.             catch (Exception e)
  66.             {
  67.                 Console.WriteLine("Exception type is {0} /n", e.GetType());
  68.             }
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement