Delete Lines From Beginning of Multiline Textbox in C#(从 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# 中的多行文本框的开头删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 C# 中的多行文本框的开头删除行


基础教程推荐
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01