TheBulgarianWolf

Replace Repeating Chars

Mar 21st, 2021
571
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ReplaceRepeatingChars
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Console.WriteLine("Enter your string here: ");
  12.             char[] charArr = Console.ReadLine().ToCharArray();
  13.             List<char> charResult = new List<char>();
  14.             charResult.Add(charArr[0]);
  15.             foreach(char ch in charArr)
  16.             {
  17.                 if(ch != charResult.Last())
  18.                 {
  19.                     charResult.Add(ch);
  20.                 }
  21.             }
  22.  
  23.             Console.WriteLine(String.Join(String.Empty,charResult));
  24.         }
  25.     }
  26. }
  27.  
RAW Paste Data