Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1. //-------------------------------
  2.         // rikiavimo funkcoja
  3.         private static void RikiuotiTeksta(string fv, string fk, char[] skyrikliai, int[] a)
  4.         {
  5.                 string[] lines = File.ReadAllLines(fv, Encoding.GetEncoding(1257));
  6.                 foreach (string line in lines)
  7.                 {
  8.                     if (line.Length > 0)
  9.                     {
  10.                         RikiuotiEilute(line, skyrikliai, fk, a);
  11.                     }
  12.                 }
  13.             foreach (string line in lines)
  14.             {
  15.                 if (line.Length > 0)
  16.                 {
  17.                     SpauzdintiManoKnyga(line, fk, a, skyrikliai);
  18.                 }
  19.             }
  20.         }
  21.         //--------------------------
  22.         //rikiuti eilute funkcija
  23.         private static void RikiuotiEilute(string line, char[] skyrikliai, string fk,int[] a)
  24.         {
  25.             string[] parts = line.Split(skyrikliai, StringSplitOptions.RemoveEmptyEntries);
  26.             for (int i = 0; i < parts.Length; i++)
  27.             {
  28.                 if (parts[i].Length >= a[i])
  29.                 {
  30.                     a[i] = parts[i].Length;
  31.                 }
  32.             }
  33.  
  34.         }
  35.         //----------------------------
  36.         //spauzidnti ManoKnyga
  37.         private static void SpauzdintiManoKnyga(string line, string fk, int[] a, char[] skyrikliai)
  38.         {
  39.          using (StreamWriter far=new StreamWriter(fk,true))
  40.             {
  41.                 string[] parts = line.Split(' ');
  42.                 for (int i = 0; i < parts.Length; i++)
  43.                 {
  44.                     if (i == 0)
  45.                         far.Write("{0,-1}", parts[0]);
  46.                     else
  47.                     {
  48.                         for (int j = 0; j < a[i - 1]+2-parts[i-1].Length; j++)
  49.                         {
  50.                             far.Write(" ");
  51.                         }
  52.                         far.Write("{0}", parts[i]);
  53.                     }
  54.                 }
  55.                 far.WriteLine();
  56.                
  57.             }
  58.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement