How to get the repeating characters of a string in C#

1 Answer

0 votes
using System;

class Program
{
     public static String get_repeating_chars(String s) { 
        int len = s.Length;
        String tmp = "";
           
        for (int i = 0; i < len; i++) { 
            for (int j = i + 1; j < len; j++) { 
                if (s[i] == s[j]) {
                    if (tmp.IndexOf(s[i], StringComparison.CurrentCultureIgnoreCase) == -1) {
                        tmp += s[i];
                        break; 
                    }
                } 
            } 
        } 
        return tmp; 
    } 
    static void Main() {
        String s = "abcdeffghijgklmbbbbxzx"; 
       
        String tmp = get_repeating_chars(s); 
        
        Console.Write(tmp);
    }
}



/*
run:

bfgx

*/

 



answered Jan 10, 2020 by avibootz

Related questions

1 answer 125 views
1 answer 136 views
1 answer 204 views
1 answer 110 views
1 answer 124 views
...