Advertisement
raziel13

string_ex_06_replacing_repeating_characters

Dec 14th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Text.RegularExpressions;
  7.  
  8. namespace _06_replace_repeating_characters//100/100
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string input = Console.ReadLine();
  15.  
  16.             var prevChar = '\0';
  17.             StringBuilder sb = new StringBuilder();
  18.             foreach (char chr in input)
  19.             {
  20.                 if (chr != prevChar)
  21.                 {
  22.                     sb.Append(chr);
  23.                     prevChar = chr;
  24.                 }
  25.             }
  26.             Console.WriteLine(sb);
  27.         }
  28.      }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement