本文整理汇总了C#中TextBlock.RemoveIfEndingWith方法的典型用法代码示例。如果您正苦于以下问题:C# TextBlock.RemoveIfEndingWith方法的具体用法?C# TextBlock.RemoveIfEndingWith怎么用?C# TextBlock.RemoveIfEndingWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextBlock
的用法示例。
在下文中一共展示了TextBlock.RemoveIfEndingWith方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateTemplateBlocks
public static List<TemplateBlock> CreateTemplateBlocks(this string content, List<StatementExprBlock> statementBlocks)
{
var blocks = new List<TemplateBlock>();
if (content.IsNullOrEmpty()) return blocks;
int pos;
var lastPos = 0;
while ((pos = content.IndexOf('@', lastPos)) != -1)
{
var contentBlock = content.Substring(lastPos, pos - lastPos);
var prevTextBlock = new TextBlock(contentBlock);
blocks.Add(prevTextBlock);
pos++; //@
if (content[pos] == '@')
{
prevTextBlock.Content += "@";
pos++;
}
else if (content[pos] == StatementPlaceholderChar)
{
pos++; //^
var index = content.GetNextAlphaNumericExpr(ref pos);
int statementNo;
if (int.TryParse(index, out statementNo))
{
var statementIndex = statementNo - 1;
if (statementIndex >= statementBlocks.Count)
throw new ArgumentOutOfRangeException(
"Expected < " + statementBlocks.Count + " but was " + statementIndex);
var statement = statementBlocks[statementIndex];
blocks.Add(statement);
}
//Strip everything but @^1 in <p>@^1</p>\n
prevTextBlock.RemoveIfEndingWith(UnwantedPrefix);
content.SkipIfNextIs(ref pos, UnwantedSuffix);
content.SkipIfNextIs(ref pos, "\r");
content.SkipIfNextIs(ref pos, "\n");
}
else
{
//ignore email addresses with @ in it
var charBeforeAtSymbol = content.SafePeekAt(pos - 3);
if (!charBeforeAtSymbol.IsAlphaNumeric())
{
var memberExpr = content.GetNextMemberExpr(ref pos);
if (memberExpr != null)
{
blocks.Add(new MemberExprBlock(memberExpr));
}
}
else
{
prevTextBlock.Content += "@";
}
}
lastPos = pos;
}
if (lastPos != content.Length)
{
var lastBlock = lastPos == 0 ? content : content.Substring(lastPos);
blocks.Add(new TextBlock(lastBlock));
}
return blocks;
}