Untitled
unknown
plain_text
3 years ago
1.7 kB
10
Indexable
using System;
using System.IO;
class Program
{
static char[] Kropki(char[] t1, string kropka)
{
string stop = "STOP";
char[] stopChar = stop.ToCharArray();
char kropa = '.';
int ilosc_kropek = 0;
for(int i = 0 ; i < t1.Length; i++)
{
if (t1[i] == kropa)
{
ilosc_kropek++;
}
}
char[] tabOut = new char[t1.Length + ilosc_kropek*stop.Length];
Console.WriteLine("Dlugosc nowej tablicy: " + (t1.Length + ilosc_kropek * stop.Length));
int j = 0;
for(int i = 0; i < t1.Length; i++)
{
if (t1[i] == kropa)
{
for(int k = 0; k < stop.Length; k++)
{
Console.WriteLine("tabOut[j] = stopChar[k]: " + stopChar[k]);
tabOut[j] = stopChar[k];
j++;
}
}
else
{
Console.WriteLine("tabOut[j] = t1[i]: " + t1[i]);
tabOut[j] = t1[i];
j++;
}
}
return tabOut;
}
static void Main(string[] args)
{ /* Napisz metodę usuwającą wszystkie kropki z wczytanego pliku tekstowego
zastępując je słowem STOP i zapisze zmiany na plik. */
string pliczek1 = "D:\\Zuza\\pliczek1.txt";
string tekst = File.ReadAllText(pliczek1);
char[] t1 = tekst.ToCharArray();
string kropka = ".";
Console.WriteLine(Kropki(t1, kropka));
File.WriteAllText(pliczek1, string.Join("", Kropki(t1, kropka)));
Console.ReadKey();
}
}Editor is loading...