且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从两个字符串之间的字符串数组中获取子字符串和char“

更新时间:2023-02-12 18:57:24

拆分不这样的工作!

可能你想要的是:

Split doesn't work like that!
Possibly what you want is:
int count = 0;
foreach (string item in list)
    {
    string[] arr1 = item.Split(new char[] {'"'}, StringSplitOptions.RemoveEmptyEntries);
    foreach (string s in arr1)
        {
        Console.WriteLine(s);
        count = count + 1;
        }
    }


问题不是很清楚。但是, String.split 返回一个数组,因此你不能将结果存储在 arr1 [count] 中,因为那是一个字符串参考。不是字符串[] 引用。同样为什么要打印 item 在下一行,而不是一些拆分数据?您可能需要执行以下操作:

The issue is not really clear. However, String.split returns an array, so you cannot store the result in arr1[count], since that is a string reference. not a string[] reference. Similarly why are you printing item in the next line, rather that some split data? You probably need to do something like:
foreach (string item in list)
{
    string[] splits = item.Split(new Char[] { '"','"' });
// do something with the split subitems
}


目前还不清楚你想用这个代码做什么,但它可以简化。

It is not clear what you want to do with this code, but it can be simplified.
int count = 0;
string[] arr1 = new string[reply.Length-20];
foreach (string item in list)
    {
       arr1[count] = item.Split(new Char[] { '"','"' });
       Console.WriteLine(item);
       count = count + 1;
    }



您对变量 count