gpt4 book ai didi

c# - 在 C# 中根据空格拆分字符串

转载 作者:行者123 更新时间:2023-11-30 19:36:44 24 4
gpt4 key购买 nike

我有一个字符串“dexter is good annd bad”。

我想通过根据空格拆分此字符串来创建一个列表。

我用下面的代码实现了这个

string ss = "dexter is  good    annd        bad";
var s = !string.IsNullOrEmpty(ss) && ss!= "null"? ss.Split(' ').ToList(): new List<string>();

问题是这个列表也包含空格,我的列表中不需要空格或空字符串。

最佳答案

您可以使用String.Split 方法:

var s = ss.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

关于c# - 在 C# 中根据空格拆分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42959965/

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