删除C#线从多行TextBox的开始 [英] Delete Lines From Beginning of Multiline Textbox in C#

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

问题描述

有没有在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.

修改 - 更多详情
在我的应用程序中的多行文本框被禁用(即它只能由应用程序本身可编辑),每行以一个\r\\\

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 "\r\n".

推荐答案

这是一个不完整的问题。因此,假设您正在使用文本框或RichTextBox中您可以使用href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.textboxbase.lines.aspx\"> 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#线从多行TextBox的开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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