gpt4 book ai didi

c# - 系统参数超出范围异常 : startIndex cannot be larger than length of string

转载 作者:太空狗 更新时间:2023-10-29 20:51:47 27 4
gpt4 key购买 nike

我有这个代码。我正在尝试仅检索文本“第一个程序”。考虑到我知道索引为 25,字符串的总长度为 35。

string text="Hello world ! This is my first program";

Response.Write(text.SubString(25,35));

但我在运行时遇到错误“System.ArgumentOutOfRangeException:startIndex 不能大于字符串的长度”

最佳答案

String.Substring 的参数是:

public string Substring(int startIndex, int length)

您正试图在第 26 个字符(startIndex 从零开始) 之后获取 35 个字符,这超出了范围。

如果您只想从第 25 个字符到字符串末尾,请使用 text.SubString(24)

关于c# - 系统参数超出范围异常 : startIndex cannot be larger than length of string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9813039/

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