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


C# Match.First方法代码示例

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


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

示例1: Template

        private static IEnumerable<string> Template(string source, Match[] matches)
        {
            if (matches.Length == 0)
                yield return source;
            else
            {
                var head = matches.First();
                var tail = matches.Skip(1).ToArray();
                var items = head.Result("$1").Split(',').Select(x => x.Trim()).ToList();
                var templates = Template(source, tail).ToList();

                foreach (var template in templates)
                    foreach (var item in items)
                        yield return template.Remove(head.Index, head.Length).Insert(head.Index, item);
            }
        }
开发者ID:baralong,项目名称:forklift,代码行数:16,代码来源:Extensions.cs

示例2: Main


//.........这里部分代码省略.........
                //Regex r = new Regex("Attachment ID ([0-9]*): type 'application/.+font', size [0-9]+ bytes, file name '(.+)'");
                ////System.Diagnostics.Debugger.Break();

                //foreach (var line in mkvmergeLines)
                //{
                //    var result = r.Match(line);
                //    if (result.Success)
                //    {
                //        ExecuteAndReturn("mkvextract", string.Format("attachments \"{0}\" {1}:\"{2}\"", item, result.Groups[1].Value, result.Groups[2].Value));
                //        if (!File.Exists("C:\\tools\\ffmpeg\\fonts\\" + result.Groups[2].Value))
                //            File.Copy(result.Groups[2].Value, "C:\\tools\\ffmpeg\\fonts\\" + result.Groups[2].Value);
                //        cleanup.Add(result.Groups[2].Value);
                //    }

                //}

                tmp = ExecuteAndReturn("ffmpeg", string.Format(" -i \"{0}\"", item));
                Regex r = new Regex("Input #0, .+?, from '" + Regex.Escape(item) + "':.+", RegexOptions.Singleline);

                var result = r.Match(tmp);
                tmp = result.Value;
                r = new Regex("\\s{4}Stream #0:(?<TrackID>[0-9])+(\\((?<language>[^()]+)\\))?: (?<Type>Video|Audio|Subtitle|Attachment):[^\\r\\n]+\\r\\n(\\s{4}Metadata:\\r\\n\\s{6}filename\\s*:\\s*(?<FileName>[^\\r\\n]+)\\r\\n\\s{6}mimetype[^\\r\\n]+)?", RegexOptions.Singleline);
                var resultCollection = r.Matches(tmp);
                //Stream #0:0: Video: mpeg4 (XVID / 0x44495658), yuv420p, 640x480, 23.98 fps, 23.98 tbr, 23.98 tbn, 23.98 tbc
                //Stream #0:1(English[eng]): Audio: vorbis, 48000 Hz, stereo, fltp, 176 kb/s
                //Stream #0:2(Japanese[jpn]): Audio: vorbis, 48000 Hz, stereo, fltp, 176 kb/s
                //Stream #0:3(English[eng]): Subtitle: text
                Match[] a = new Match[resultCollection.Count];
                resultCollection.CopyTo(a, 0);

                string audioTrack = "a";
                if (a.Count(g => g.Groups["Type"].Value == "Audio") > 1)
                {
                    var audioResult = a.Where(g => g.Groups["Type"].Value == "Audio").FirstOrDefault(g => g.Value.Contains("jpn") || g.Value.Contains("Japanese"));
                    if (audioResult != null)
                        audioTrack = audioResult.Groups["TrackID"].Value;
                }
                bool hasSubs = false;

                var subtitleResult = a.FirstOrDefault(g => g.Groups["Type"].Value == "Subtitle");
                if (File.Exists(item+".ass"))
                {
                    hasSubs = true;

                    subtitlefile = item + ".ass";

                }
                else if (subtitleResult != null)
                {
                    ExecuteAndReturn("ffmpeg", string.Format("-i \"{0}\" -y  -vn -an -codec:s:0.{1} ssa  \"{2}\"", item, subtitleResult.Groups["TrackID"].Value, subtitlefile));//-codec:s:0.{1}
                    hasSubs = true;
                    cleanup.Add(subtitlefile);
                }

                if (a.Count(g => g.Groups["Type"].Value == "Attachment") > 0)
                {
                    ExecuteAndReturn("ffmpeg", string.Format("-dump_attachment:t \"\" -i \"{0}\" -y", item), dir);

                    foreach (var f in a.Where(g => g.Groups["Type"].Value == "Attachment").Select(g => g.Groups["FileName"].Value))
                    {
                        cleanup.Add(dir + "\\" + f);
                        if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + Settings.Default.FontPath + f))
                        {
                            if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory+Settings.Default.FontPath))
                                Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + Settings.Default.FontPath);
                            File.Copy(dir + "\\" + f, AppDomain.CurrentDomain.BaseDirectory + Settings.Default.FontPath + f);
开发者ID:Jiyuu,项目名称:Mobilez,代码行数:67,代码来源:Program.cs


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