c# - C#超出范围的子字符串
问题描述
我尝试像这样填充字符串[]:
public string Reception = "";
public void SaveData()
{
int lengthReception = Reception.Length; //i got 19
string[] Data = new Data[lengthReception];
for(int i = lengthReception, i>0, i--)
{
Data[i] = Reception.Substring(i,1); //i try to store one charactere by case
} //but i got error message ArgumentOutOfRangeException
}
所以我想逐个存储一个字符。根据 doc microsoft,我的 Substring 看起来不错?!
谢谢你的帮助!
解决方案
如果Reception.Length
是,则索引或更高19
处没有字符。19
这有效:
public void SaveData()
{
int lengthReception = Reception.Length; //= 19
string[] Data = new string[lengthReception];
for (int i = lengthReception - 1; i >= 0; i--)
{
Data[i] = Reception.Substring(i, 1);
}
}
推荐阅读
- amazon-web-services - CodePipeline 未将所有文件保存在源工件中
- css - 位置属性是否覆盖显示属性?
- r - r中的奇怪矩阵行为
- android - android sqlitedatabasehelper 数据库未找到问题/错误
- radiance - 有没有“你好世界!” 光辉的例子?
- java - 为什么这个简单的 Junit 5 测试不起作用
- sql - 使用 T-SQL 按能力级别组织团队,但一个团队具有混合能力级别
- php - 即使在特定日期没有访问,如何编辑此查询以获得最近 7 天的访问?
- java - 将字节数组转换为带分隔符的十六进制字符串?删除字符串中显示的最后一个字符?
- c++ - ld:未找到架构 x86_64 qt 的符号