Truncated Text using ToCharArray()

Posted on 2008-11-03
Last Modified: 2013-12-17
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)



                            List<string> subconcept = new List<string>();

                            string remove = "TreeNode: ";

                            string modSubconcept ="";


                            foreach(string str in subconcept)

                            modSubconcept = str.Trim(remove.ToCharArray());



Open in new window

Question by:MichelleLacy
    LVL 17

    Expert Comment

    modSubconcept = str.Remove(remove,"");
    LVL 3

    Assisted Solution


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

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


    Author Comment

    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.

    Accepted Solution

    I figured out the solution using the following code:

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

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    This video discusses moving either the default database or any database to a new volume.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now