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

方案一:

使用while循环:

  static void Main(string[] args)
{
string s = "aeiou";
string s2 = "welecome to Quantum Asia";
char[] array = s.ToCharArray();
for (int i = ; i < array.Length; i++)
{
while (true)
{
var index = s2.IndexOf(array[i]);
if (index == -) break;
s2 = s2.Remove(index, );
}
}
Console.WriteLine(s2);
Console.ReadKey();
}

方案二:

递归:

  static void Main(string[] args)
{
string s = "aeiou";
string s2 = "welecome to Quantum Asia";
char[] array = s.ToCharArray(); for (int i = ; i < array.Length; i++)
{
s2 = GetStr2(array[i], s2);
}
Console.WriteLine(s2);
Console.ReadKey();
} private static string GetStr2(char v, string s2)
{
var index = s2.IndexOf(v);
if (index != -)
{
s2 = s2.Remove(index, );
s2 = GetStr2(v, s2);
}
return s2;
}
05-23 06:54