[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Truncated Text using ToCharArray()

Posted on 2008-11-03
4
Medium Priority
?
544 Views
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)
                        {
                            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

0
Comment
Question by:MichelleLacy
  • 2
4 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 22871979
try
modSubconcept = str.Remove(remove,"");
0
 
LVL 3

Assisted Solution

by:trunghieubkit
trunghieubkit earned 2000 total points
ID: 22873012
using

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


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

0
 

Author Comment

by:MichelleLacy
ID: 22873315
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
 

Accepted Solution

by:
MichelleLacy earned 0 total points
ID: 22873475
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

873 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