次の方法で共有


EditPoint2.DeleteWhitespace(vsWhitespaceOptions) Method

Definition

Deletes the empty characters (white space) horizontally or vertically around the current location in the text buffer.

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)

Parameters

Direction
vsWhitespaceOptions

Optional. A vsWhitespaceOptions constant that determines how and where to remove empty spaces.

Implements

Attributes

Examples

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);  
        }  
    }  
}  

Remarks

DeleteWhitespace removes white (empty) space around the edit point or TextSelection without first copying the text to the clipboard. If Direction is vsWhitespaceOptionsHorizontal, then DeleteWhitespace deletes spaces and tab characters on both sides of the edit point to the beginning and end of the edit point's line, or until a non-white-space character is encountered. If Direction is vsWhitespaceOptionsVertical, then DeleteWhitespace deletes blank lines on both sides of the edit point to the beginning and end of the document, or until a non-blank line is encountered. If Direction is vsWhitespaceOptionsVertical, and the current line is not blank, then this method does nothing.

Applies to