В строке S одну последовательность символов заменить другой - C#
Формулировка задачи:
Здравствуйте, помогите, пожалуйста, решить задачу. Задание: В строке S одну последовательность символов заменить другой.
using System;
namespace Prog1
{
class Program
{
static void Main()
{
Console.WriteLine("Введите строку :");
string s = Console.ReadLine();
char[] myChars = s.ToCharArray();
Console.WriteLine("Что заменить? :");
string s1 = Console.ReadLine();
char[] myChars1 = s1.ToCharArray();
Console.WriteLine("На что заменить :");
string s2 = Console.ReadLine();
char[] myChars2 = s2.ToCharArray();
for (int i = 0; i < s.Length; i++)
{
if (myChars[i] == myChars1[i])
{
s = s.Replace(myChars1[i], myChars2[i]);
}
}
Console.WriteLine(s);
Console.ReadKey();
}
}
}Решение задачи: «В строке S одну последовательность символов заменить другой»
textual
Листинг программы
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Введите строку :");
string s = Console.ReadLine();
Console.WriteLine("Что заменить? :");
string s1 = Console.ReadLine();
Console.WriteLine("На что заменить :");
string s2 = Console.ReadLine();
Console.WriteLine(s.Replace(s1, s2));
Console.ReadKey();
}
}