Truncated Text using ToCharArray()

I have pulling the text from tree nodes and adding them to List<>.  I have a method that grabs the text from the 2nd node for database querying and 3rd node for visualiation in another control, it removes specific text "TreeNode: " from the 2nd node (n2), before adding it to the List.  The problem is, that it is truncating the text.  Is there something I should be using instead of ToCharArray()?
...
...
public static List<string> trimSubconcept = new List<string>();
 
private void btnSelectExp_Click(object sender, EventArgs e)
        {
            foreach (TreeNode n1 in treeView1.Nodes)
                foreach (TreeNode n2 in n1.Nodes)
                    foreach (TreeNode n3 in n2.Nodes)
                        if (n3.Checked)
                        {
                            lstbxItems.Items.Add(n3.Text);
 
                            List<string> subconcept = new List<string>();
                            string remove = "TreeNode: ";
                            string modSubconcept ="";
                            subconcept.Add(n2.ToString());
                            foreach(string str in subconcept)
                            modSubconcept = str.Trim(remove.ToCharArray());
                            trimSubconcept.Add(modSubconcept);
                        }

Open in new window

MichelleLacyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mokuleCommented:
try
modSubconcept = str.Remove(remove,"");
0
trunghieubkitCommented:
using

modSubconcept = str.Replace(remove, "");


your solution have some mistakes
if  str = "TreeNode: eeeerrrTTTTNNNNNoo" or some strings like this
=> modSubconcept = ""

0
MichelleLacyAuthor Commented:
The string I want to remove will always be the same.  Is there a way to search for the entire substring "TreeNode: " without breaking it into characters?  Trunghieubkit you are right.  If any of the characters in "TreeNode: " appear in text that I want to keep, it will be removed.  And that is exactly what is happening.
0
MichelleLacyAuthor Commented:
I figured out the solution using the following code:

List<string> subconcept = new List<string>();
string modSubconcept ="";
subconcept.Add(n2.ToString());
foreach (string str in subconcept)
modSubconcept = str.Remove(0, 9).Trim();
trimSubconcept.Add(modSubconcept);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.