Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C行中使用子字符串#_C#_Split_Substring - Fatal编程技术网

C# 在C行中使用子字符串#

C# 在C行中使用子字符串#,c#,split,substring,C#,Split,Substring,我在使用substring方法时遇到问题,出现此错误 “索引和长度必须引用字符串中的位置。” “参数名称:长度” 这意味着传递给子字符串的值对于调用它们的字符串无效。例如: string s = "hello"; string x = s.Substring(0, 1); // <-- This is fine (returns "h") string y = s.Substring(1, 3); // <-- Also fine (returns "ell") string z

我在使用substring方法时遇到问题,出现此错误

“索引和长度必须引用字符串中的位置。” “参数名称:长度”
这意味着传递给
子字符串的值对于调用它们的字符串无效。例如:

string s = "hello";

string x = s.Substring(0, 1); // <-- This is fine (returns "h")
string y = s.Substring(1, 3); // <-- Also fine (returns "ell")
string z = s.Substring(5, 3); // <-- Throws an exception because 5 is passed
                              //     the end of 's' (which only has 5 characters)
我认为人们对
Split
方法的签名感到困惑。以下几点就足够了:

item.Split(' ')

只需转到错误行,并查看值…解决方案的可能重复:学会。您是否确实尝试过自己调试它?您需要将此行拆分并调试它,然后您就会发现问题
item.Split(new char[]{' '})
item.Split(' ')