Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cutting from string in C#

My strings look like that: aaa/b/cc/dd/ee . I want to cut first part without a / . How can i do it? I have many strings and they don't have the same length. I tried to use Substring(), but what about / ?

I want to add 'aaa' to the first treeNode, 'b' to the second etc. I know how to add something to treeview, but i don't know how can i receive this parts.

like image 966
user449921 Avatar asked Dec 21 '10 15:12

user449921


1 Answers

Maybe the Split() method is what you're after?

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.

Based on your updates related to a TreeView (ASP.Net? WinForms?) you can do this:

foreach(string text in collection)
{
    TreeNode node = new TreeNode(text);
    myTreeView.Nodes.Add(node);
}
like image 62
hunter Avatar answered Oct 09 '22 01:10

hunter