从TextBox的开头删除特定的行号 [英] Removing Specific Line Numbers From The Start Of TextBox
本文介绍了从TextBox的开头删除特定的行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好b $ b
所以我想知道如何从一开始就从多行文本框的开头删除特定行号。
i知道它会是这样的
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 = "";
}
请帮我解决这个问题吧:)总是如此谢谢/>
编辑:所以很多行已导入到多行文本框中,我想要的是一旦导入行以从中移除x行数停止文本框是更好的?这就是我上面尝试的代码。
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.
推荐答案
// 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());
// 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++;
}
这篇关于从TextBox的开头删除特定的行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文