共用方式為


RecognizedWordUnit.DisplayAttributes 屬性

定義

取得格式化資訊,這項資訊會用來從目前的 RecognizedWordUnit 執行個體建立文字輸出。

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 物件內容中要顯示的空白區的用法。

範例

下列範例會顯示公用程式常式 (stringFromWordArray) ,它會產生以三種方式之一格式化的字串 (:使用 LexicalForm) 、使用 (標準化) Text ,或使用 (的發音) Pronunciation 。 文字輸出是從物件上的 DisplayAttributes 屬性取得 ReadOnlyCollection<T> RecognizedWordUnit ,而這些物件是從 Words 物件上的屬性取得 RecognizedPhrase

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 會指定要搭配指定單字使用的開頭和尾端空格(如果有的話)。

如需如何使用此格式化資訊的詳細資訊,請參閱 DisplayAttributes 列舉。

適用於

另請參閱