Freigeben über


RecognizedWordUnit.DisplayAttributes Eigenschaft

Definition

Ruft Formatierungsinformationen ab, die zum Erstellen der Textausgabe aus der aktuellen RecognizedWordUnit Instanz verwendet werden.

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

Eigenschaftswert

Gibt die Verwendung von Leerzeichen an, um den Inhalt eines RecognizedWordUnit Objekts anzuzeigen.

Beispiele

Das folgende Beispiel zeigt eine Hilfsroutine (stringFromWordArray), die eine Zeichenfolge generiert, die auf eine von drei Arten formatiert ist: lexikalisch (mithilfe LexicalForm), normalisiert (mithilfe Text) oder phonetisch (mithilfe Pronunciation). Die Textausgabe wird aus der DisplayAttributes Eigenschaft eines ReadOnlyCollection<T> Objekts RecognizedWordUnit abgerufen, das von der Words Eigenschaft eines RecognizedPhrase Objekts abgerufen wird.

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;
}

Hinweise

Das DisplayAttributes von der DisplayAttributes Eigenschaft zurückgegebene Objekt gibt ggf. die führenden und nachfolgenden Leerzeichen an, die mit einem bestimmten Wort verwendet werden sollen.

Weitere Informationen zur Verwendung dieser Formatierungsinformationen finden Sie in der DisplayAttributes Enumeration.

Gilt für:

Weitere Informationen