当前位置: 首页>>代码示例>>C#>>正文


C# TextBlock.RemoveIfEndingWith方法代码示例

本文整理汇总了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;
		}
开发者ID:yuinlin,项目名称:ServiceStack,代码行数:71,代码来源:TemplateExtensions.cs


注:本文中的TextBlock.RemoveIfEndingWith方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。