My lines look like this: aaa / b / cc / dd / ee. I want to cut the first part without /. How should I do it? I have many lines, and they do not have the same length. I tried using 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 a treeview, but I do not know how I can get these parts.
Perhaps the Split () method is what you are after?
string value = "aaa/b/cc/dd/ee"; string[] collection = value.Split('/');
Defines substrings in this instance that are limited to one or more characters specified in the array, and then places the substrings in an array of strings.
, TreeView (ASP.Net? WinForms?), :
foreach(string text in collection) { TreeNode node = new TreeNode(text); myTreeView.Nodes.Add(node); }
Substring IndexOf, /
Substring
IndexOf
/
:
// from memory, need to test :) string output = String.Substring(inputString, 0, inputString.IndexOf("/"));
// from memory, need to test :) string output = String.Substring(inputString, inputString.IndexOf("/"), inputString.Length - inputString.IndexOf("/");
, , :
string[] parts = "aaa/b/cc/dd/ee".Split(new char[] { '/' });
, ... !
- string.Split , string.Join , , .
string.Split
string.Join
var parts = input.Split('/'); var processedInput = string.Join("/", parts.Skip(1));
. , string.IndexOf, :
string.IndexOf
var processedInput = input.Substring(input.IndexOf('/') + 1);
Source: https://habr.com/ru/post/1781477/More articles:PHP moving bits into code? - phpHow to model multiple inheritance objects in Java - javaHow to sort std :: map? - functorArchiving a changed array - noNotRecognizeSelector exception - immutabilityUsing an indentifier or a reserved word in an automation object under FPC - delphiHow do you avoid a reserved word in Free-Pascal? - delphiHow to assign NULL to optional parameters in VB.NET 1.1 - vb.netC # Byte [] Encryption - c #Is jQuery e.target suitable for best practice? - jquerymysql определяет размер хранилища поля - databaseAll Articles