本文整理匯總了C#中System.Xml.Linq.XText.Remove方法的典型用法代碼示例。如果您正苦於以下問題:C# XText.Remove方法的具體用法?C# XText.Remove怎麽用?C# XText.Remove使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.Linq.XText
的用法示例。
在下文中一共展示了XText.Remove方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: AddWordMarkup
/// <summary>
/// Adds word level markup to an <see cref="XText"/>
/// </summary>
/// <param name="textNode">The <see cref="XText"/></param>
/// <param name="wordElementName">The name of the element to mark up words with</param>
/// <param name="wordClassName">The class attribute value for word markup elements</param>
/// <param name="idPrefix">A prefix for id attributes of word markup elements</param>
/// <returns>A <see cref="bool"/> indicating if any word level markup was actually added</returns>
public static bool AddWordMarkup(XText textNode, XName wordElementName, string wordClassName, string idPrefix)
{
var doc = textNode.Document;
var ids = doc == null
? new HashSet<string>()
: new HashSet<string>(doc.Descendants().Attributes(IdAttributeName).Select(a => a.Value));
var expr = new Regex(@"\b\w+\b");
if (expr.Matches(textNode.Value).Count <= 1) return false;
var match = expr.Match(textNode.Value);
while (match.Success)
{
if (match.Index > 0) textNode.AddBeforeSelf(new XText(textNode.Value.Substring(0, match.Index)));
var wordElem = new XElement(wordElementName, GetIdAttr(ids, idPrefix), match.Value);
if (!String.IsNullOrWhiteSpace(wordClassName))
{
wordElem.SetAttributeValue("class", wordClassName);
}
textNode.AddBeforeSelf(wordElem);
textNode.Value = textNode.Value.Substring(match.Index + match.Length);
if (textNode.Value.Length == 0) textNode.Remove();
match = expr.Match(textNode.Value);
}
return true;
}