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


C# Regex.Cast方法代码示例

本文整理汇总了C#中System.Text.RegularExpressions.Regex.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# Regex.Cast方法的具体用法?C# Regex.Cast怎么用?C# Regex.Cast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Text.RegularExpressions.Regex的用法示例。


在下文中一共展示了Regex.Cast方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NumberOfMentionsInTweet

 private static int NumberOfMentionsInTweet(string account, string tweetText)
 {
     const string twitterAccountPattern = @"@[A-Za-z0-9_]{1,15}";
     var matches = new Regex(twitterAccountPattern).Matches(tweetText);
     return
         matches.Cast<object>().Count(match =>(account.IndexOf(match.ToString(), StringComparison.CurrentCultureIgnoreCase) < 0));
 }
开发者ID:gyakhnin,项目名称:TweetAggregator,代码行数:7,代码来源:AggregationService.cs

示例2: CommandHandler

        public static void CommandHandler(object sender, ExecutedRoutedEventArgs ea)
        {
            ea.Handled = true;
            var mainWindow = (MainWindow)Application.Current.MainWindow;
            var tweet = ea.Parameter as Tweet ?? mainWindow.Timeline.GetSelectedTweet;
            if (tweet == null) return;
            if (tweet.IsDirectMessage)
            {
                mainWindow.Compose.ShowDirectMessage(tweet.ScreenName);
            }
            else
            {
                var matches = new Regex(@"(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9_]+)")
                    .Matches(tweet.Text);

                var names = matches
                    .Cast<Match>()
                    .Where(m => m.Groups[1].Value != tweet.ScreenName)
                    .Where(m => m.Groups[1].Value != Settings.Default.ScreenName)
                    .Select(m => "@" + m.Groups[1].Value)
                    .Distinct();

                var replyTos = string.Join(" ", names);
                var message = string.Format("@{0} {1}{2}", tweet.ScreenName, replyTos, (replyTos.Length > 0) ? " " : "");
                mainWindow.Compose.Show(message, tweet.StatusId);
            }
        }
开发者ID:arvydas,项目名称:tweetz-desktop,代码行数:27,代码来源:ReplyCommand.cs

示例3: ResolveProjectFilesFrom

        private IEnumerable<IProjectInfo> ResolveProjectFilesFrom(FileInfo file)
        {
            IEnumerable<IProjectInfo> projects;
            using (var reader = new StreamReader(file.OpenRead()))
            {
                var content = reader.ReadToEnd();
                var matches = new Regex("[.A-Za-z0-9\\\\]*.csproj").Matches(content);

                projects = matches.Cast<Match>()
                    .Where(match => File.Exists(string.Format("{0}\\{1}", file.DirectoryName, match.Value)))
                    .Select(match => ProjectInfoFrom(file, match));
            }
            return projects;
        }
开发者ID:chrisjowen,项目名称:ResolveIt,代码行数:14,代码来源:SolutionLoader.cs

示例4: ReplaceImg

        internal static string ReplaceImg(string html)
        {
            var originalImages = new Regex(@"<img([^>]+)>").Matches(html);
            originalImages.Cast<Match>().Each(image =>
                {
                    var img = image.Value;
                    var src = AttributeParser(img, "src");
                    var alt = AttributeParser(img, "alt");
                    var title = AttributeParser(img, "title");

                    html = html.Replace(img, string.Format(@"![{0}]({1}{2})", alt, src, (title.Length > 0) ? string.Format(" \"{0}\"", title) : ""));
                });

            return html;
        }
开发者ID:huoxudong125,项目名称:Html2Markdown,代码行数:15,代码来源:HtmlParser.cs

示例5: ReplaceAnchor

        public static string ReplaceAnchor(string html)
        {
            var originalAnchors = new Regex(@"<a[^>]+>[^<]+</a>").Matches(html);
            originalAnchors.Cast<Match>().Each(anchor =>
                {
                    var a = anchor.Value;
                    var linkText = GetLinkText(a);
                    var href = AttributeParser(a, "href");
                    var title = AttributeParser(a, "title");

                    html = html.Replace(a, string.Format(@"[{0}]({1}{2})", linkText, href, (title.Length > 0) ? string.Format(" \"{0}\"", title) : ""));
                });

            return html;
        }
开发者ID:huoxudong125,项目名称:Html2Markdown,代码行数:15,代码来源:HtmlParser.cs

示例6: ReplacePre

        internal static string ReplacePre(string html)
        {
            var preTags = new Regex(@"<pre\b[^>]*>([\s\S]*)<\/pre>").Matches(html);

            return preTags.Cast<Match>().Aggregate(html, ConvertPre);
        }
开发者ID:huoxudong125,项目名称:Html2Markdown,代码行数:6,代码来源:HtmlParser.cs

示例7: SortChapterByName

        internal static string SortChapterByName(MangaChapter arg)
        {
            var matches = new Regex(@"(([0-9])*[0-9])").Matches(arg.Name);
            if (matches.Count < 1) return "";

            return arg.Name.Substring(0, arg.Name.IndexOf(matches[0].Value)) + matches.Cast<Match>().Select(n => n.Value.PadLeft(3, '0')).Aggregate((m, n) => m + n);
        }
开发者ID:koneta,项目名称:MangaPortal,代码行数:7,代码来源:MangaController+(ASUS's+conflicted+copy+2014-04-07).cs

示例8: GetUnsubstitutedSettings

 private static IList<string> GetUnsubstitutedSettings(string content)
 {
     var matches = new Regex(@"(?<!`)\${([^}]*)}").Matches(content);
     return (matches.Cast<object>().Select(match => match.ToString())).ToList();
 }
开发者ID:rnarayana,项目名称:PowerUp,代码行数:5,代码来源:SettingsSubstitutor.cs

示例9: ResolveProjectFilesFrom

        private IList<IProjectFile> ResolveProjectFilesFrom(string content)
        {
            var matches = new Regex("[.A-Za-z0-9\\\\]*.csproj").Matches(content);

            var projectFiles =  matches.Cast<Match>()
                    .Select(match => ProjectFile.Load(string.Format("{0}\\{1}", Path, match.Value)))
                    .Cast<IProjectFile>().ToList();

            if (projectFiles.IsEmpty()) throw new NoProjectsInSolutionComplaint(this);
            return projectFiles;
        }
开发者ID:chrisjowen,项目名称:ResolveIt,代码行数:11,代码来源:SolutionFile.cs

示例10: ReplaceCode

		public static string ReplaceCode(string html)
		{
			var singleLineCodeBlocks = new Regex(@"<code>([^\n]*?)</code>").Matches(html);
			singleLineCodeBlocks.Cast<Match>().ToList().ForEach(block =>
			{
				var code = block.Value;
				var content = GetCodeContent(code);
				html = html.Replace(code, string.Format("`{0}`", content));
			});

			var multiLineCodeBlocks = new Regex(@"<code>([^>]*?)</code>").Matches(html);
			multiLineCodeBlocks.Cast<Match>().ToList().ForEach(block =>
			{
				var code = block.Value;
				var content = GetCodeContent(code);
				content = IndentLines(content).TrimEnd() + Environment.NewLine + Environment.NewLine;
				html = html.Replace(code, string.Format("{0}    {1}", Environment.NewLine, TabsToSpaces(content)));
			});

			return html;
		}
开发者ID:Leafney,项目名称:Html2Markdown,代码行数:21,代码来源:HtmlParser.cs


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