Прочетете на английски Редактиране

Споделяне чрез


RecognizedWordUnit.DisplayAttributes Property

Definition

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

C#
public System.Speech.Recognition.DisplayAttributes DisplayAttributes { get; }

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.

C#
internal enum WordType
{
  Text,
  Normalized = Text,
  Lexical,
  Pronunciation
}
C#
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

Продукт Версии
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

See also