manikandan r

manikandan r

  • NA
  • 358
  • 0

how to find a repeated characters in a Word

Mar 18 2021 1:12 AM
 write a function to find repeated characters in a Word and then add "$" symbol like below
 input - hellow   output -  he$l$low
 
 

Answers (1)

1
Sachin Singh

Sachin Singh

  • 8
  • 55.8k
  • 84k
Mar 18 2021 7:22 AM
This is very easy to achieve, just think in terms of characters
  1. static void Main(string[] args)  
  2.   
  3.        {  
  4.   
  5.            string input = "hellow";  
  6.            string input1 = null;  
  7.            var arr = input.ToCharArray();  
  8.            foreach(char c in arr)  
  9.            {  
  10.                if(input.Count(x=>x==c)>=2)  
  11.                {  
  12.   
  13.                     input1 = input.Replace(c.ToString(), "$" + c.ToString());  
  14.                    
  15.                }  
  16.            }  
  17.   
  18.            Console.WriteLine(input1);  
  19.            Console.ReadLine();  
  20.   
  21.        } 
 
Accepted Answer