gpt4 book ai didi

c# - 在 C# 中从字符串中剪切

转载 作者:太空狗 更新时间:2023-10-30 00:16:56 25 4
gpt4 key购买 nike

我的字符串看起来像这样:aaa/b/cc/dd/ee。我想在没有/的情况下剪切第一部分。我该怎么做?我有很多字符串,但它们的长度不同。我尝试使用 Substring(),但是/呢?

我想将“aaa”添加到第一个 treeNode,将“b”添加到第二个等等。我知道如何向 treeview 添加一些内容,但我不知道如何接收这些部分。

最佳答案

也许是 Split()方法是您所追求的?

string value = "aaa/b/cc/dd/ee";

string[] collection = value.Split('/');

Identifies the substrings in this instance that are delimited by one or more characters specified in an array, then places the substrings into a String array.

根据与 TreeView(ASP.Net?WinForms?)相关的更新,您可以这样做:

foreach(string text in collection)
{
TreeNode node = new TreeNode(text);
myTreeView.Nodes.Add(node);
}

关于c# - 在 C# 中从字符串中剪切,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4501109/

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