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
Значение свойства
Указывает использование пробела для отображения содержимого RecognizedWordUnit объекта.
Примеры
В следующем примере показана подпрограмма служебной программы (stringFromWordArray), которая создает строку, отформатированную одним из трех способов: лексически (используя LexicalForm), нормализовано (с помощью Text) или фонетически (с помощью Pronunciation). Выходные данные текста получаются из свойства объектаReadOnlyCollection<T>, полученного RecognizedWordUnit из DisplayAttributesWords свойства объекта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 перечислении.