Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mod

Status
Not open for further replies.

rstum2005

Programmer
Jun 9, 2005
117
US
Can anyone tell me what Im doing wrong here? Id like to take out every other '\n'. Also the "count" is the number of lines in the richtextbox.

for (int i=0;i<=count;i++)
{
char t = '\n';
if (i % 2 == 0)
{
richTextBox1.Text.IndexOf(t,i,1);
}
}

"Success consists of going from failure to failure without loss of enthusiasm."
Winston Churchill~
 
I don't know about richtextboxes but using a regular textbox I got this to work

Code:
public void RemoveEveryOtherLine(bool remove)
{
string txt = textBox1.Text;
			int index = 0;

			for (int i = 0; i < txt.Length; i++)
			{
				if (index >= 0)
				{
					index = txt.IndexOf("\r\n", index, txt.Length - index);
				}

				if (index >= 0)
				{
					if (remove)
					{
						txt = txt.Remove(index, 2);
						index += 2;
					}
					remove = !remove;
				}
			}

			textBox1.Text = txt;
}


Remove is set by the calling code. If it is set to true

RemoveEveryOtherLine(true);

then the 1st, 3rd, 5th, 7th, etc \r\n will be removed.

otherwise (false) the 2nd, 4th, 6th, 8th etc will be removed.


Hope this works for you.
 
Thanks a bunch! When I get a chance I will take a look at it and get back with you,


Ron

"Success consists of going from failure to failure without loss of enthusiasm."
Winston Churchill~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top