Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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
 
if (TextBox.Text.Equals(StringNumber/s))
{
  TextboxName.Text = "";
}
 

please help me get this code right Smile | :) 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 11-May-13 5:56am
Edited 11-May-13 6:51am
v2
Comments
OriginalGriff at 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.
ThePhantomUpvoter at 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?
fatslice90 at 11-May-13 11:51am
   
updated the question
JSMW at 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?
fatslice90 at 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 :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

			// 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());
  Permalink  
v5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

// 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++;
			}
  Permalink  

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

  Print Answers RSS
0 BillWoodruff 360
1 Mathew Soji 309
2 DamithSL 225
3 Afzaal Ahmad Zeeshan 202
4 Maciej Los 190
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web02 | 2.8.1411019.1 | Last Updated 13 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100