用c#程序编写:创建一个字符串数组,数组元素由键盘输入,输出那些含c的字符串
1个回答
展开全部
下面这段程序 应该符合你的要求: 有两个,你看看吧
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace Exist_A
{
public class Test
{
public void test()
{
string Result;
string[] str =new string[5];
for (int i = 0; i < 5; i++)
{
str[i] = Console.ReadLine();
}
test1(str);
}
public void test1(string[] str)
{
for (int i = 0; i < 5; i++)
{
foreach (char s in str[i])
{
if (s == 'a')
{
Console.WriteLine(str[i]);
break;
}
}
}
}
}
class Program
{
static void Main(string[] args)
{
Test ts = new Test();
ts.test();
}
}
}
这个用到正则表达式的:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace Exist_A
{
public class Test
{
public void test()
{
string[] str =new string[5];
for (int i = 0; i < 5; i++)
{
str[i] = Console.ReadLine();
}
test1(str);
}
public void test1(string[] str)
{
string path = "c";
Regex reg = new Regex(path);
for (int i = 0; i < 5; i++)
{
foreach (Match match in reg.Matches(str[i])) //遍历str[i]找到符合条件的
{
//Console.WriteLine("{0}",match.Value);
Console.WriteLine(str[i]);
break;
}
}
}
}
class Program
{
static void Main(string[] args)
{
Test ts = new Test();
ts.test();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace Exist_A
{
public class Test
{
public void test()
{
string Result;
string[] str =new string[5];
for (int i = 0; i < 5; i++)
{
str[i] = Console.ReadLine();
}
test1(str);
}
public void test1(string[] str)
{
for (int i = 0; i < 5; i++)
{
foreach (char s in str[i])
{
if (s == 'a')
{
Console.WriteLine(str[i]);
break;
}
}
}
}
}
class Program
{
static void Main(string[] args)
{
Test ts = new Test();
ts.test();
}
}
}
这个用到正则表达式的:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace Exist_A
{
public class Test
{
public void test()
{
string[] str =new string[5];
for (int i = 0; i < 5; i++)
{
str[i] = Console.ReadLine();
}
test1(str);
}
public void test1(string[] str)
{
string path = "c";
Regex reg = new Regex(path);
for (int i = 0; i < 5; i++)
{
foreach (Match match in reg.Matches(str[i])) //遍历str[i]找到符合条件的
{
//Console.WriteLine("{0}",match.Value);
Console.WriteLine(str[i]);
break;
}
}
}
}
class Program
{
static void Main(string[] args)
{
Test ts = new Test();
ts.test();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询