Permutations of capitalization

前端 未结 8 650
生来不讨喜
生来不讨喜 2020-12-21 01:24

I want to build a list containing every possible permutation of capitalization of a word. so it would be

List permutate(string word)
{
    List         


        
8条回答
  •  鱼传尺愫
    2020-12-21 01:53

    You can modify individual characters if you convert your string to an array of char. Something like this should do the trick...

    public static List Permute( string s )
    {
      List listPermutations = new List();
    
      char[] array = s.ToLower().ToCharArray();
      int iterations = (1 << array.Length) - 1;
    
      for( int i = 0; i <= iterations; i++ )
      {
        for( int j = 0; j < array.Length; j++ )
        array[j] = (i & (1<

提交回复
热议问题