Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Cut
Run
Expand Minimize

WordRight Method (TextSelection Object)

Visual Studio .NET 2003

Moves the selected text right the specified number of words.

[Visual Basic .NET]
Public Sub WordRight( _
   Optional ByVal Extend As Boolean = False, _
   Optional ByVal Count As Integer = 1 _
) 
[Visual Basic 6]
Sub WordRight( _
   Optional ByVal Extend As Boolean = False, _
   Optional ByVal Count As Long = 1 _
) 
[C++]
HRESULT __stdcall WordRight(
   VARIANT_BOOL Extend,
   long Count
);
[C#]
public void WordRight(
   bool Extend,
   int Count
);
[JScript .NET]
public function WordRight(
   Extend : Boolean,
   Count : int
)

Parameters

Extend
Optional. Determines whether the moved text is collapsed or not. The default is False.
Count
Optional. Represents the number of words to move right. The default value is 1.

Remarks

If Extend is True, then the active end of the selected text is moved right Count number of words. Otherwise, the selected text is collapsed and positioned Count words right from the active end. If the end of the document is encountered before Count words, then the position remains at the end of the document.

If the value of Count is negative, then WordRight peforms like the WordLeft Method.

The active language manager for the text document defines the meaning of a "word."

Example

Sub WordRightExample()
    ' Before running this example, open a text document.
    Dim objSel As TextSelection = DTE.ActiveDocument.Selection
    If objSel.IsEmpty Then
        ' If there is no text selected, swap the words before and after 
        ' the insertion point. We begin by selecting the word before the 
        ' insertion point.
        objSel.WordLeft(True)
        If Not objSel.IsEmpty Then
            ' We can continue only if the selection was not already at the 
            ' beginning of the document.
            Dim strBefore As String = objSel.Text

            ' The text is saved in strBefore; now delete it and move past 
            ' the following word.
            objSel.Delete()
            objSel.WordRight(True)
            If objSel.Text.StartsWith(" ") Or objSel.Text.StartsWith(Microsoft.VisualBasic.ControlChars.Tab) Then
                ' The previous call to WordRight may have skipped some 
                ' white space instead of an actual word. In that case, we 
                ' should call it again.
                objSel.WordRight(True)
            End If

            ' Insert the new text at the end of the selection.
            objSel.Insert(strBefore, vsInsertFlags.vsInsertFlagsInsertAtEnd)
        End If
    Else
        ' If some text is selected, replace the following word with the 
        ' selected text.
        Dim strSelected As String = objSel.Text

        objSel.MoveToPoint(objSel.BottomPoint)
        objSel.WordRight(True)
        If objSel.Text.StartsWith(" ") Or objSel.Text.StartsWith(Microsoft.VisualBasic.ControlChars.Tab) Then
            ' The previous call to WordRight may have skipped some 
            ' white space instead of an actual word. In that case, we 
            ' should call it again.
            objSel.WordRight(True)
        End If

        ' Insert the text, overwriting the existing text and leaving the 
        ' selection containing the inserted text.
        objSel.Insert(strSelected, vsInsertFlags.vsInsertFlagsContainNewText)
    End If
End Sub

See Also

Applies To: TextSelection Object

Show:
© 2015 Microsoft