gpt4 book ai didi

c# - 忽略字符串数组的第一项

转载 作者:行者123 更新时间:2023-11-30 20:59:00 25 4
gpt4 key购买 nike

如何忽略第一个itemstring[]如果是 if (item=="")我的代码像

string[] temp3 = clearstring.Split(new string[]{@",","\r\n","\n","]", "\"", "}"}, StringSplitOptions.None);
temp.Close();

StreamWriter sW = new StreamWriter(Npath);

foreach (string item in temp3)
{
if (item == "")
{
}

最佳答案

使用 StringSplitOptions.RemoveEmptyEntries

string[] temp3 = clearstring.Split(new string[]{@",","\r\n","\n","]", "\"", "}"}, StringSplitOptions.RemoveEmptyEntries);

编辑: 仅忽略第一个空字符串的选项:

for(int i=0; i<temp3.Length; i++)
{
string item = temp3[i];
if(i==0 && item == string.Empty)
continue;

//do work
}

关于c# - 忽略字符串数组的第一项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15681158/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com