Writing assistance features significantly speed up the writing process by providing auto-correction, auto-completion, and key phrase replacement, saving time and reducing errors to create a professional document or letter. In particular, pre-designed and phrased sentences that are inserted frequently improve the user experience of such applications.

This sample shows how to replace the word at the current input position with content retrieved from a Web API.

Web API

To simulate the phrase replacement, the following Web API method ReplaceWord accepts a string and returns a value from a dictionary:

Loading...

This Web API method is called from JavaScript in the asynchronous method replaceWord:

Loading...

Replacing the Selection

When the user presses F8, the word at the input position is selected and retrieved. This word is then sent to the Web API to retrieve the replacement string. This string will eventually be loaded into the selection to replace the current string.

Loading...

The following screen video shows the replacement in action.

Phrase replacement

You can test this yourself by downloading the Visual Studio project from our GitHub repository.