Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
In main form I have a textBox, a radioButton (here I've set Apprerance to Button). The thing is I want when I click on that radioButton every word (that is in the textBox) will be deleted one by one. How can I do that? Thanks in advanced!
Posted

hi phabion,

you can simply split the value in your text box by using space as a splitter

Then u can remove each value in each loop. see below sample:

C#
private void button1_Click(object sender, EventArgs e)
{
    string sValue = textBox1.Text;
    string[] arrValues = sValue.Split(new char[] { ' ' });
    for (int i = 0; i < arrValues.Length; i++)
    {
        arrValues[i] = arrValues[i].ToString().Replace(arrValues[i].ToString(), "");
    }
    for (int o = 0; o < arrValues.Length; o++)
    {
        textBox1.Text = arrValues[o].ToString();
    }
}



Thanks
Chageie
 
Share this answer
 
Why one by one?

Which end of the string should deletion start from?

You have experience in Borlands' products so how would you have done it there? Write out the steps you would have taken, in pseudo code, and then
try to implement them in C#. When/if you get stuck ask again showing your code and asking specific questions.
 
Share this answer
 
Hi phabion,

What is your requirement of removing the words one by one? Is there any specific reason? Can you please elaborate it? Because, it will be easier and more user friendly if you remove the whole bunch of text from your TextBox at a time.

If you still want to remove the words one by one, first write the algorithm in a piece of paper and try to implement it in your code.

If you face any issue for a piece of code, don't hesitate to post it here. Thank you for posting it at CodeProject.
 
Share this answer
 
Hi Phabion,

For this you have to set radio buttons autopostback property to 'true'

and register its oncheckedchanged event.

protected void rbtn_CheckedChanged(object sender, EventArgs e)
   {
       if (rbtn.Checked)
       {
           rbtn.Checked = false;
       }
       else
       {
           rbtn.Checked = true;
       }
       if(txtText.Text.Contains(" "))
       {
           txtText.Text = txtText.Text.Substring(0, txtText.Text.LastIndexOf(" "));
       }
       else
       {
           txtText.Text = "";
       }
   }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900