Удаление подстроки с помощью регулярных выражений - C#
Формулировка задачи:
using System;
using System.Collections.Generic;
using System.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string f = Console.ReadLine();
if (f.Length > 6)
{
string q = f.Substring(0, 6); //удаляет все символы после шестого и формирует новую строку
string p = f.Remove(0, 6); // удаляет первые 6 символов и формирует новую строку
Console.WriteLine(q + "{" + p + "}"); // выводим и заключаем в скобки только то, что после первых шести
}
Console.ReadLine();
Console.ReadKey();
}
}
}Решение задачи: «Удаление подстроки с помощью регулярных выражений»
textual
Листинг программы
string f = Console.ReadLine();
if (f.Length > 6)
{
Regex befor_6 = new Regex(@"^[\w\s]{6}");
Match match_befor_6 = befor_6.Match(f);
string after = match_befor_6.Value;
Regex after_6 = new Regex(@"(?<=^[\w\s]{6})[\w\s]+");
Match mact_after_6 = after_6.Match(f);
string befor = mact_after_6.Value;
Console.WriteLine(after + "{" + befor + "}");
}