ISpellCheckService.GetSpellingSuggestions(String) Method
Generates suggestions on how to replace a misspelled word.
Namespace: DevExpress.Blazor.RichEdit
Assembly: DevExpress.Blazor.v24.2.dll
NuGet Package: DevExpress.Blazor
Declaration
string[] GetSpellingSuggestions(
string word
)
Parameters
Name | Type | Description |
---|---|---|
word | String | A misspelled word. |
Returns
Type | Description |
---|---|
String[] | An array of suggestions. |
Remarks
If the CheckWordSpelling(String) method determines that a word is misspelled, the Rich Text Editor passes the misspelled word to the GetSpellingSuggestions
method. This method should build and return a spelling suggestion array. The context menu displays the generated suggestions, if any. If the method returns an empty array, the context menu displays No suggestions.
The MaxSuggestionCount property specifies the maximum number of suggestions the context menu should display. For instance, if you set this property to 3
, the context menu displays up to 3 suggestions. If the GetSpellingSuggestions
method generates more than 3 suggestions, the context menu displays only the first 3 suggestions from the array.
The following code snippet implements an ISpellCheckService interface:
using DevExpress.Blazor.RichEdit;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
public class MySpellCheckService : ISpellCheckService {
public CultureInfo Culture { get; set; }
public bool AddToDictionaryEnabled { get; }
public int MaxSuggestionCount { get; }
string PathToDictionary { get;}
List<string> CorrectWords { get;}
public MySpellCheckService(string path) {
PathToDictionary = path;
Culture = CultureInfo.InvariantCulture;
AddToDictionaryEnabled = true;
MaxSuggestionCount = 7;
CorrectWords = File.ReadLines(PathToDictionary).ToList();
CorrectWords.Sort();
}
public void AddToDictionary(string word) {
if (Culture.TwoLetterISOLanguageName == "en") {
word = word.ToLower();
int placeToInsert = CorrectWords.BinarySearch(word);
CorrectWords.Insert(placeToInsert, word);
File.AppendAllText(PathToDictionary, word + '\n');
}
}
public bool CheckWordSpelling(string word) {
if (Culture.TwoLetterISOLanguageName == "en") {
int index = CorrectWords.BinarySearch(word.ToLower());
return (index >= 0);
}
return false;
}
public string[] GetSpellingSuggestions(string word) {
List<string> suggestions = new List<string>();
// Generate suggestions and add them to the list
return suggestions.ToArray();
}
}
Refer to the following topic for more information about the built-in spell check service: Spell Check.