c#编写一个函数,输出两个字符串的公有字符串

来源:百度知道 编辑:UC知道 时间:2024/06/07 00:37:56
static string f(char[] s1, char[] s2)
{
string s="";
for (int i = 0; i < s1.Length; i++)
{
for (int j = 0; j < s2.Length; j++)
{
if (s2[j] == s1[i])
s += s2[j].ToString();
}
}
return s;
}

我的写法如上,我总觉得不舒服,因为输入参数是字符型的数组,而返回值是个string类型的,哪位帮我改下,改成这个样子的就好了
static string f(string s1, string s2)
{
...
}
回答都正确,多谢各位仁兄.我要问的问题解决了..但是我的程序逻辑还有问题。我把它改成这个样子后
static string f(string s1, string s2)
{
string s = "";
for (int i = 0; i < s1.Length; i++)
{
for (int j = 0; j < s2.Length; j++)
{
if (s2[j] == s1[i])
{
s += s1[i].To

可以直接改成static string f(string s1, string s2)
原程序不用改动
C#支持字符串的索引 例如stirng s1="abc";
s1[0]就表示"a";

static string f(string s1, string s2)
{
string s="";
for (int i = 0; i < s1.Length; i++)
{
for (int j = 0; j < s2.Length; j++)
{
if (s2[j] == s1[i])
s += s2[j].ToString();
}
}
return s;
}

static string f(string s1, string s2) {
string s = "";
for (int i = 0; i < s2.Length; i++) {
if (s1.IndexOf(s2[i]) != -1) s = s + s2[i];
}
return s;
}

static string f(string s1, string s2)
{
string s = "";
for (int i = 0; i < s1.Length; i++)
{

请编写两个函数:一个是将5位int型数转换为每两个字符间加一个 编写一个函数由实参传来一个字符串统计数字,空格和其他字符的个数在主函数中输入字符串以及输出上述结果 编写程序,输入一个三位整数,输出对应的字符 C语言程序:写一个函数,输入一个4位数字,要求输出这4个数字字符,每两个数字字符间 编写一个函数,重复打印给定的字符N次. 编写一个函数fun,它的功能是:删除字符串中的数字字符。例如:输入的字符串为:123abc67de89f输出为abcde 编写一个函数,输出整数m的所有因子 <New>写一函数,输入一个4位数字,要求输出这4个数字字符,但每两个数字间空一个空格 C#关于字符的输出问题(初学) 用C#编写两个程序!!!