【发布时间】:2017-01-05 07:13:00
【问题描述】:
如果我发现列表中存在相等字符串的字符串索引:
int index = myList.FindIndex(x => x.StartsWith(inputStr));
什么是接近字符串 +1 -1 并将其替换为某个值的正确且快速的方法:
如此理想的结果,如果我的列表内容是:
0. hello world 1
1. hello world 2
2. hello world 3
3. hello world 4
并且输入字符串等于“hello world 2”,我希望通过索引 +1 “hello world 3”或 -1 “hello world 1”找到 +1 -1 索引并将其替换为“X”或只是将字符串作为变量用于其他用途。
0. hello world 1
1. hello world 2
2. X
3. hello world 4
【问题讨论】:
-
请注意,
line => line == input表示您搜索等于input的行,而使用x => x.StartsWith(inputStr)您只检查该行是否以input字符串开头。 -
您在这里面临的困难是什么?