从 C# 中的多行文本框的开头删除行 [英] Delete Lines From Beginning of Multiline Textbox in C#

查看:53
本文介绍了从 C# 中的多行文本框的开头删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 C# 中是否有一种优雅的方式可以从多行文本框的开头删除多行文本?我正在使用 Microsoft Visual C# 2008 Express Edition.

Is there a graceful way in C# to delete multiple lines of text from the beginning of a multiline textbox? I am using Microsoft Visual C# 2008 Express Edition.

编辑 - 其他详细信息我的应用程序中的多行文本框被禁用(即它只能由应用程序本身编辑),并且每一行都以 "结尾.

EDIT - Additional Details The multiline textbox in my application is disabled (i.e. it is only editable by the application itself), and every line is terminated with a " ".

推荐答案

这是一个不完整的问题.因此,假设您使用 TextBox 或 RichTextBox,您可以使用 TextBoxBase 中的 Lines 属性.

This is an incomplete question. So assuming you are using either TextBox or RichTextBox you can use the Lines property found inTextBoxBase.

//get all the lines out as an arry
string[] lines = this.textBox.Lines;

然后您可以使用此数组并将其重新设置.

You can then work with this array and set it back.

  this.textBox.Lines= newLinesArray;

这可能不是最优雅的方式,但它会删除第一行.您不需要选择,只需使用跳过就可以了

This might not be the most elegant way, but it will remove the first line. you don't need select, just using skip will be fine

    //number of lines to remove from the beginning
    int numOfLines = 30; 
    var lines = this.textBox1.Lines;
    var newLines = lines.Skip(numOfLines);

    this.textBox1.Lines = newLines.ToArray();

这篇关于从 C# 中的多行文本框的开头删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆