gpt4 book ai didi

c# - 如何使用 LINQ 从 C# 中的列表中的所有字符串中删除子字符串

转载 作者:行者123 更新时间:2023-11-30 19:33:39 25 4
gpt4 key购买 nike

我有一个字符串列表

"00000101000000110110000010010011",
"11110001000000001000000010010011",

我需要从每个字符串中删除前 4 个字符

所以结果列表会像

"0101000000110110000010010011",
"0001000000001000000010010011",

有什么方法可以使用 LINQ 来做到这一点吗?

最佳答案

strings = strings.Select(s => s.Substring(4)).ToList();

如果字符串长度不是至少四个字符,这将抛出一个 ArgumentOutOfRange 异常,所以你可能想做类似的事情

strings = strings.Where(s => s.Length >= 4).Select(s => s.Substring(4)).ToList();

删除太短的字符串。

关于c# - 如何使用 LINQ 从 C# 中的列表中的所有字符串中删除子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3298933/

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