DisplayAttributes Enumeration

Describes formatting for printed output of words of a recognized phrase.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

Namespace: System.Speech.Recognition
Assembly: System.Speech (in system.speech.dll)

public enum DisplayAttributes
/** @attribute FlagsAttribute() */ 
public enum DisplayAttributes
public enum DisplayAttributes

 Member nameDescription
ConsumeLeadingSpacesIndicates that any spaces preceding the given word should be removed. 
OneTrailingSpaceIndicates that there should be one trailing space following the given word.  
TwoTrailingSpacesIndicates that there should be two trailing space following the given word. 
ZeroTrailingSpacesIndicates that there should be no trailing space following the given word. 

Instances of DisplayAttributes are obtained by through RecognizedWordUnit.DisplayAttributes and ReplacementText.DisplayAttributes.

Two or more members of the DisplayAttributes enumeration may be combined by a bit-wise OR to specify how a particular word should be displayed.

Under Windows Desktop Speech, a phrases are specified by collections of RecognizedWordUnit or ReplacementText objects; each object corresponds to a single word or punctuation mark.

The print spacing of these words and punctuation marks is determined by the value of the DisplayAttributes assigned to each RecognizedWordUnit or ReplacementText.

For example, suppose the input phrase to a recognition engine using the default system grammar provided by DictationGrammar is "Hello comma he said period".

Then the recognition engine will return a RecognizedPhrase containing five RecognizedWordUnit objects containing the following strings and values of DisplayAttributes.




OneTrailingSpace | ConsumeLeadingSpaces






OneTrailingSpace | ConsumeLeadingSpaces

The text returned for this recognized phrase would then be printed as: "Hello, he said."

The following example shows a utility method that returns a formatted phrase from a collection of RecognizedWordUnits returned by a recognition engine.

static string GetDisplay(ReadOnlyCollection<RecognizedWordUnit> Words) {
    StringBuilder sb = new StringBuilder();
    DisplayAttributes displayAttribute;
    string text;
    for (int i = 0; i < Words.Count; i++) {

        displayAttribute = Words[i].DisplayAttributes;
        text = Words[i].Text;

        // Remove leading spaces
        if ((displayAttribute & DisplayAttributes.ConsumeLeadingSpaces) != 0) {
            while (sb.Length > 0 && char.IsWhiteSpace(sb[sb.Length - 1])) {
                sb.Remove(sb.Length - 1, 1);

        // Append text

        // Add trailing spaces
        if ((displayAttribute & DisplayAttributes.ZeroTrailingSpaces) != 0) {
            // no action
        } else if ((displayAttribute & DisplayAttributes.OneTrailingSpace) != 0) {
            sb.Append(" ");
        } else if ((displayAttribute & DisplayAttributes.TwoTrailingSpaces) != 0) {
            sb.Append("  ");
    return sb.ToString().Trim();

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions