c# 两个字符串,s="aeiou",s2="welcome to Quantum Asia"

c#  两个字符串,s="aeiou",s2="welcome to Quantum Asia"

方案一:

使用while循环:

 1  static void Main(string[] args)
 2         {
 3             string s = "aeiou";
 4             string s2 = "welecome to Quantum Asia";
 5             char[] array = s.ToCharArray();
 6             for (int i = 0; i < array.Length; i++)
 7             {
 8                 while (true)
 9                 {
10                     var index = s2.IndexOf(array[i]);
11                     if (index == -1) break;
12                     s2 = s2.Remove(index, 1);
13                 }
14             }
15             Console.WriteLine(s2);
16             Console.ReadKey();
17         }

方案二:

 递归:

 1  static void Main(string[] args)
 2         {
 3             string s = "aeiou";
 4             string s2 = "welecome to Quantum Asia";
 5             char[] array = s.ToCharArray();
 6 
 7             
 8             for (int i = 0; i < array.Length; i++)
 9             {
10                 s2 = GetStr2(array[i], s2);
11             }
12             Console.WriteLine(s2);
13             Console.ReadKey();
14         }
15 
16         private static string GetStr2(char v, string s2)
17         {
18             var index = s2.IndexOf(v);
19             if (index != -1)
20             {
21                 s2 = s2.Remove(index, 1);
22                 s2 = GetStr2(v, s2);
23             }
24             return s2;
25         }
原文地址:https://www.cnblogs.com/zlp520/p/6743055.html