using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication14
{
class Program
{
static void Main(string[] args)
{
Console.Write("filename = ");
string filename = Console.ReadLine();
if (File.Exists(filename))
{
FileStream fp = new FileStream(filename, FileMode.Open);
StreamReader reader = new StreamReader(fp);
Console.WriteLine("masukan kata yg ingin diganti :");
string n = (Console.ReadLine());
Console.WriteLine("masukan kata yg ingin menggantikan :");
string m = (Console.ReadLine());
string data;
int e = 0;
while ((data = reader.ReadLine()) != null)
{
string[] kata = data.Split(' ');
for (int i = 0; i <= kata.Length - 1; i++)
{
int r = (kata[i].IndexOf(n));
if (r >= 0)
{
kata[i] = m;
Console.Write(" {0}", kata[i]);
}
else
{
Console.Write(" {0}", kata[i]);
}
}
Console.WriteLine();
}
reader.Close();
fp.Close();
Console.WriteLine(e);
}
else
Console.WriteLine("file is not found!");
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication14
{
class Program
{
static void Main(string[] args)
{
Console.Write("filename = ");
string filename = Console.ReadLine();
if (File.Exists(filename))
{
FileStream fp = new FileStream(filename, FileMode.Open);
StreamReader reader = new StreamReader(fp);
Console.WriteLine("masukan kata yg ingin diganti :");
string n = (Console.ReadLine());
Console.WriteLine("masukan kata yg ingin menggantikan :");
string m = (Console.ReadLine());
string data;
int e = 0;
while ((data = reader.ReadLine()) != null)
{
string[] kata = data.Split(' ');
for (int i = 0; i <= kata.Length - 1; i++)
{
int r = (kata[i].IndexOf(n));
if (r >= 0)
{
kata[i] = m;
Console.Write(" {0}", kata[i]);
}
else
{
Console.Write(" {0}", kata[i]);
}
}
Console.WriteLine();
}
reader.Close();
fp.Close();
Console.WriteLine(e);
}
else
Console.WriteLine("file is not found!");
}
}
}
No comments:
Post a Comment