这是我做的:
// this is an example of my function, the string and the remover should be variables
string delimeter = ",";
string remover="4";
string[] separator = new string[] { "," };
List<String> List = "1,2,3,4,5,6".Split(separator, StringSplitOptions.None).ToList();
for (int i = 0; i < List.Count - 1; i++)
{
if(List[i]==remover)
List.RemoveAt(i);
}
string allStrings = (List.Aggregate((i, j) => i + delimeter + j));
return allStrings;
Run Code Online (Sandbox Code Playgroud)
问题是重新编译的字符串与原始字符串相同,与"1,2,3,4,5,6"相同."4"仍在其中.
怎么解决?
编辑:
解决方案是我没有检查列表中的最后一个节点,因为它在示例中看起来不像是因为它是我刚才给出的一个例子