从行首删除空格 [英] remove spaces from beginning of lines
本文介绍了从行首删除空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 vb.net 项目和我在多行文本框中有文本像这样
i have a vb.net project and i have text in a multi-line textbox like this
abc
def
ghi
jkl
mn
每一行都以空格开头我想从所有行中删除初始空格
every line starts with spaces i want to remove the initial spaces from all line
我试过了
For Each lne In TextBox1.Lines
If lne.StartsWith(" ") Then
TextBox1.Text = TextBox1.Text.Replace(" ", "")
End If
Next
但是它会删除文本框中的其他文本并且不起作用
but it deletes other texts in the text box and won't work
推荐答案
你可以使用这个:
Dim result As String = ""
For Each lne In TextBox1.Lines
result += lne.TrimStart() & Environment.NewLine
Next
TextBox1.Text = result
上述方法使用了String.TrimStart()
函数删除每一行的前导空格.
The above method uses the String.TrimStart()
function to remove the leading whitespaces from each line.
这篇关于从行首删除空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文