EditPoint2.DeleteWhitespace(vsWhitespaceOptions) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
删除文本缓冲区中当前位置周围的水平方向或垂直方向的空字符(空格)。
void DeleteWhitespace(EnvDTE::vsWhitespaceOptions Direction = EnvDTE.vsWhitespaceOptions.vsWhitespaceOptionsHorizontal);
[System.Runtime.InteropServices.DispId(166)]
public void DeleteWhitespace (EnvDTE.vsWhitespaceOptions Direction = EnvDTE.vsWhitespaceOptions.vsWhitespaceOptionsHorizontal);
[<System.Runtime.InteropServices.DispId(166)>]
abstract member DeleteWhitespace : EnvDTE.vsWhitespaceOptions -> unit
Public Sub DeleteWhitespace (Optional Direction As vsWhitespaceOptions = EnvDTE.vsWhitespaceOptions.vsWhitespaceOptionsHorizontal)
参数
- Direction
- vsWhitespaceOptions
可选。 vsWhitespaceOptions 常数,它确定移除空白的方式和位置。
实现
- 属性
示例
Sub DeleteWhitespaceExample(ByVal dte As DTE2)
' Create a new text file.
dte.ItemOperations.NewFile()
' Create an EditPoint at the start of the new document.
Dim doc As TextDocument = _
CType(dte.ActiveDocument.Object("TextDocument"), TextDocument)
Dim point As EditPoint = doc.StartPoint.CreateEditPoint
Dim i, j As Integer
' Insert 10 lines of text.
For i = 1 To 10
point.Insert("This is a test." & vbCrLf)
Next
If MsgBox("Remove all spaces between words?", MsgBoxStyle.YesNo) _
= MsgBoxResult.Yes Then
point.StartOfDocument()
For i = 1 To 10
For j = 1 To 3
point.WordRight()
point.DeleteWhitespace( _
vsWhitespaceOptions.vsWhitespaceOptionsHorizontal)
Next
point.StartOfLine()
point.LineDown()
Next
End If
End Sub
public void DeleteWhitespaceExample(DTE2 dte)
{
// Create a new text file.
dte.ItemOperations.NewFile(@"General\Text File", "",
Constants.vsViewKindPrimary);
// Create an EditPoint at the start of the new document.
TextDocument doc =
(TextDocument)dte.ActiveDocument.Object("TextDocument");
EditPoint point = doc.StartPoint.CreateEditPoint();
// Insert 10 lines of text.
for (int i = 1; i <= 10; ++i)
point.Insert("This is a test.\n");
if (MessageBox.Show("Remove all spaces between words?", "",
MessageBoxButtons.YesNo) == DialogResult.Yes)
{
point.StartOfDocument();
for (int i = 1; i <= 10; ++i)
{
for (int j = 1; j <= 3; ++j)
{
point.WordRight(1);
point.DeleteWhitespace(
vsWhitespaceOptions.vsWhitespaceOptionsHorizontal);
}
point.StartOfLine();
point.LineDown(1);
}
}
}
注解
DeleteWhitespace 删除编辑点附近的空白 (空) 空间 TextSelection ,或者不首先将文本复制到剪贴板。 如果 Direction 为 vsWhitespaceOptionsHorizontal ,则将 DeleteWhitespace 在编辑点的两侧删除空格和制表符,并删除编辑点线条的开头和结尾,或直到遇到非空白字符。 如果 Direction 为 vsWhitespaceOptionsVertical ,则 DeleteWhitespace 在编辑点的两侧删除空白行到文档的开头和结尾,或在遇到非空白行时删除。 如果 Direction 为 vsWhitespaceOptionsVertical ,并且当前行不为空,则此方法不执行任何操作。