【发布时间】:2015-05-14 05:46:12
【问题描述】:
所以我有一个名为 page 的字符串数组和一个名为 notesSplit 的字符串数组,它是使用 notes.split() 创建的。
notessplit 可以有可变数量的换行符,但永远不会超过 10 行。
如果 notessplit 中不存在索引,我想覆盖索引 20 - 30 中“页面”的内容,留下空白行。
有什么想法吗?
var page = new string[44]; <-- actually this is from a text file
string notes = "blah \n blah \n";
string[] notesSplit = notes.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
我最初想出的是:
for (var i = 0; i < 9; i++)
{
if (notesSplit[i] != null)
{
Page[i + 20] = notesSplit[i];
} else {
Page[i + 20] = System.Environment.NewLine;
}
}
【问题讨论】:
-
请解释清楚,显示示例输入和所需输出
-
“索引不存在”是什么意思?你的意思是它超出了数组的范围吗?还是没有内容?
-
Merging two arrays in .Net 的可能重复项
-
@ZoharPeled 你认为他为什么要合并数组?
-
“如果索引在 notessplit 中不存在,我想覆盖索引 20 - 30 中“页面”的内容,留下空白行。” 在我看来将 notesSplit 数组合并到 notesArray