您的位置:首页 > 编程语言 > C#

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

2017-04-21 12:57 357 查看
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 = 0; i < array.Length; i++)
{
while (true)
{
var index = s2.IndexOf(array[i]);
if (index == -1) break;
s2 = s2.Remove(index, 1);
}
}
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 = 0; 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 != -1)
{
s2 = s2.Remove(index, 1);
s2 = GetStr2(v, s2);
}
return s2;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐