Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
So i was wondering how do you remove specific line number from the start of a multi line textbox from the start.

i know it would be something like this

C#
if (TextBox.Text.Equals(StringNumber/s))
{
  TextboxName.Text = "";
}



please help me get this code right :) thanks as always

edit: so a lot of lines has been imported in to a multi line textbox and what i am wanting is once the lines has been imported to remove x amount of lines from the stop of the textbox is that better? that is the code i have tried above.
Posted
Updated 11-May-13 5:51am
v2
Comments
OriginalGriff 11-May-13 11:09am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Perhaps if you give an example, rather than two unrelated lines of code?
Use the "Improve question" widget to edit your question and provide better information.
[no name] 11-May-13 11:11am    
Yep... sure will be something like that. What is the actual code that you have tried? What is the input you are trying? What is the expected output? What is the actual output that you get?
[no name] 11-May-13 11:51am    
updated the question
JMaxwell88 11-May-13 12:16pm    
are you attempting to remove specific lines (separated by newline characters) or sets of substrings denoted by start-point and length?
[no name] 11-May-13 12:20pm    
i am just attempting to remove specifc x amount of lines from the top of the text box which is a multi line text box :)

C#
			// input string:..
			String testText = @"This 
is 
my 
test 
text 
string";

			// number of lines to take away from the result
			int toRemove = 2;

			// turn the input string into an array (split by newlines)
			List<string> testLines = new List<String>(testText.Split(new String[] { Environment.NewLine }, StringSplitOptions.None));		

			// counter for the number of lines already removed
			for (int lineNo = 0; lineNo < toRemove; lineNo++)
			{
				// remove the line in question
				testLines.RemoveAt(0);
			}

			// compund the result with newline character strings into one
			textBox1.Text = String.Join(Environment.NewLine, testLines.ToArray());
 
Share this answer
 
v5
C#
// input string:..
			String testText = @"This 
is 
my 
test 
text 
string";

			// line indexes to take away from the result
			int[] toRemove = {2, 4};

			// turn the input string into an array (split by newlines)
			List<string> testLines = new List<String>(testText.Split(new String[] { Environment.NewLine }, StringSplitOptions.None));		

			// counter for the number of lines already removed
			int backpace = 0;			
			foreach(int lineNo in toRemove)
			{
				// realign the array index counter according to the number of lines so far removed
				int in_lineNo = lineNo - backpace;
		
				// remove the line in question
				testLines.RemoveAt(in_lineNo);

				// update the lines removed counter
				backpace++;
			}
 
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