C#编程:程序的基本功能是:找出一个字符串数组中包含指定字符串的数组元素并组成新的字符串数组。
答案:2 悬赏:60
解决时间 2021-02-11 05:50
- 提问者网友:冷场帝
- 2021-02-10 12:10
C#编程:程序的基本功能是:找出一个字符串数组中包含指定字符串的数组元素并组成新的字符串数组。
最佳答案
- 二级知识专家网友:心痛成瘾
- 2021-02-10 13:16
数组不支持直接在使用中删除某个元素,所以只能先读取后重组
貌似你想对一些名称字符串根据特征字符进行归类,我给你写了一段代码,你试试
string[] orgStr=new string[]{"first","second","third"};
string tempstr=string.Empty;
for (int i = 0; i < orgStr.Count();i++ )
{
if (orgStr[i].Contains("ir"))
{
tempstr += orgStr[i] + ",";
}
}
//下面的obj_arr就是你要的数组
if (!string.IsNullOrEmpty(tempstr))
{
string[] obj_arr = tempstr.Split(new char[] { ',' },
StringSplitOptions.RemoveEmptyEntries);
}
貌似你想对一些名称字符串根据特征字符进行归类,我给你写了一段代码,你试试
string[] orgStr=new string[]{"first","second","third"};
string tempstr=string.Empty;
for (int i = 0; i < orgStr.Count();i++ )
{
if (orgStr[i].Contains("ir"))
{
tempstr += orgStr[i] + ",";
}
}
//下面的obj_arr就是你要的数组
if (!string.IsNullOrEmpty(tempstr))
{
string[] obj_arr = tempstr.Split(new char[] { ',' },
StringSplitOptions.RemoveEmptyEntries);
}
全部回答
- 1楼网友:如果这是命
- 2021-02-10 14:31
一般使用array.findall 或是 linq 方法,当然也可以使用foreach 或是 for 循环来查找但是相对麻烦一点。
示例代码见下
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯