RecognizedWordUnit.DisplayAttributes Property

Definition

Gets formatting information used to create the text output from the current RecognizedWordUnit instance.

public:
 property System::Speech::Recognition::DisplayAttributes DisplayAttributes { System::Speech::Recognition::DisplayAttributes get(); };
public System.Speech.Recognition.DisplayAttributes DisplayAttributes { get; }
member this.DisplayAttributes : System.Speech.Recognition.DisplayAttributes
Public ReadOnly Property DisplayAttributes As DisplayAttributes

Property Value

Specifies the use of white space to display of the contents of a RecognizedWordUnit object.

Examples

The following example shows a utility routine (stringFromWordArray) that generates a string that is formatted in one of three ways: lexically (using LexicalForm), normalized (using Text), or phonetically (using Pronunciation). The text output is obtained from the DisplayAttributes property on a ReadOnlyCollection<T> of RecognizedWordUnit objects, which is obtained from the Words property on a RecognizedPhrase object.

internal enum WordType   
{  
  Text,  
  Normalized = Text,  
  Lexical,  
  Pronunciation  
}  
internal static string stringFromWordArray(  
        ReadOnlyCollection<RecognizedWordUnit> words,   
        WordType type)   
{  
  string text = "";  
  foreach (RecognizedWordUnit word in words)   
  {  
    string wordText = "";  
    if (type == WordType.Text || type == WordType.Normalized)   
    {  
      wordText = word.Text;  
    }   
    else if (type == WordType.Lexical)   
    {  
      wordText = word.LexicalForm;  
    }  
    else if (type == WordType.Pronunciation)   
    {  
       wordText = word.Pronunciation;  
    }   
    else   
    {  
      throw new InvalidEnumArgumentException(  
         String.Format("[0}: is not a valid input", type));  
    }  

    // Use display attribute  
    if ((word.DisplayAttributes & DisplayAttributes.OneTrailingSpace) != 0)   
    {  
      wordText += " ";  
    }  
    if ((word.DisplayAttributes & DisplayAttributes.TwoTrailingSpaces) != 0)  
    {  
      wordText += "  ";  
    }  
    if ((word.DisplayAttributes & DisplayAttributes.ConsumeLeadingSpaces) != 0)   
    {  
      wordText = wordText.TrimStart();  
    }  
    if ((word.DisplayAttributes & DisplayAttributes.ZeroTrailingSpaces) != 0)  
    {  
      wordText = wordText.TrimEnd();  
    }  

    text += wordText;  

  }  
  return text;  
}  

Remarks

The DisplayAttributes object returned by the DisplayAttributes property specifies the leading and trailing spaces to be used with a given word, if any.

For more information about how to use this formatting information, see the DisplayAttributes enumeration.

Applies to

See also