RecognizedWordUnit.DisplayAttributes 屬性

定義

取得格式化資訊,這項資訊會用來從目前的 RecognizedWordUnit 執行個體建立文字輸出。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

屬性值

DisplayAttributes

指定 RecognizedWordUnit 物件內容中要顯示的空白區的用法。Specifies the use of white space to display of the contents of a RecognizedWordUnit object.

範例

下列範例顯示公用程式常式(stringFromWordArray),其會產生以下列三種方式之一格式化的字串:詞法(使用 LexicalForm)、正規化(使用 Text)或語音(使用 Pronunciation)。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). 文字輸出是從 RecognizedWordUnit 物件 ReadOnlyCollection<T> 上的 DisplayAttributes 屬性取得,這是從 RecognizedPhrase 物件上的 Words 屬性取得。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;  
}  

備註

DisplayAttributes 屬性所傳回的 DisplayAttributes 物件,會指定要與指定的單字搭配使用的開頭和尾端空格(如果有的話)。The DisplayAttributes object returned by the DisplayAttributes property specifies the leading and trailing spaces to be used with a given word, if any.

如需如何使用此格式資訊的詳細資訊,請參閱 DisplayAttributes 列舉。For more information about how to use this formatting information, see the DisplayAttributes enumeration.

適用於

另請參閱