Advertisement
Guest User

Untitled

a guest
Nov 19th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. namespace IT4
  7. {
  8.     class PraceSeSoubory
  9.     {
  10.         public static void cteniZeSouboru()//načte celý soubor do stringu
  11.         {
  12.             //string cesta = "C:\\Users\\robert.hajda\\Documents\\text.txt";
  13.  
  14.             string cesta = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\text.txt";
  15.             string t = File.ReadAllText(cesta);
  16.             Console.WriteLine(t);
  17.             Console.ReadLine();
  18.  
  19.  
  20.  
  21.  
  22.  
  23.         }
  24.         //****************************************************************************************Varianty:***************************************************************************************************************      
  25.         //program vrátí počet znaků ale bez mezer
  26.  
  27.         public static void cteniZeSouboru2()
  28.         {
  29.  
  30.  
  31.             string cesta = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\jarek.txt";
  32.             string t = File.ReadAllText(cesta);
  33.             Console.WriteLine(t);
  34.             int pocetMezer = 0;
  35.            
  36.             foreach (char z in t)
  37.                 if (z == ' ') pocetMezer++;
  38.  
  39.             int pocet = t.Length - pocetMezer;
  40.             Console.WriteLine("počet znaků bez mezer: " + pocet);
  41.             Console.ReadLine();
  42.         }
  43.         public static void uvod()
  44.         {
  45.             string cesta = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\jarek.txt";
  46.  
  47.             string[] soubor = File.ReadAllLines(cesta);
  48.             double soucet = 0;
  49.             foreach (string radek in soubor)
  50.             {
  51.                 Console.WriteLine(radek);
  52.                 soucet = soucet + double.Parse(radek.Substring(radek.IndexOf(' ')));
  53.                
  54.             }
  55.             Console.WriteLine(soucet);
  56.             Console.ReadLine();
  57.         }
  58.         public static void uvod33()
  59.         {
  60.             string cesta = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\jarek.txt";
  61.             double max = double.MinValue;
  62.             string[] soubor = File.ReadAllLines(cesta);
  63.             double soucet = 0;
  64.             foreach (string radek in soubor)
  65.             {
  66.                 Console.WriteLine(radek);
  67.                 double cislo = double.Parse(radek.Substring(radek.IndexOf(' ')));
  68.                 soucet = soucet + cislo;
  69.                 if (cislo == max) max = cislo;
  70.             }
  71.             Console.WriteLine(soucet);
  72.             Console.WriteLine("maxim: ");
  73.             foreach (string radek in soubor)
  74.             {
  75.                 double cislo = double.Parse(radek.Substring(radek.IndexOf(' ')));
  76.                 if (cislo == max) Console.WriteLine(radek);
  77.            
  78.             }
  79.             Console.ReadLine();
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement