Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Write a program that reads a string from the console and replaces all series of consecutive identical letters with a single one.
- namespace _01.SeriesOfLetters
- {
- using System;
- using System.Text;
- using System.Text.RegularExpressions;
- class SeriesOfLetters
- {
- static void Main(string[] args)
- {
- string text = Console.ReadLine();
- string pattern = @"(?<letter>\w)\1+";
- MatchCollection matches = Regex.Matches(text, pattern);
- StringBuilder sb = new StringBuilder(text);
- foreach (Match match in matches)
- {
- sb.Replace(match.ToString(), match.Groups["letter"].Value.ToString());
- }
- Console.WriteLine(sb);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement