Exemple #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Variant生のまま");
            var foo = new[]{
                Variant<int,string>.C1(4),
                Variant<int,string>.C2("foo")};
            foo
                .ForEach(either => either
                    .Match(
                        C1: i => i.ToString(),
                        C2: s => s)
                    .Act(Console.WriteLine));

            //Option<T> = Variant<Unit,T>
            Console.WriteLine("\nOption");
            var hoge = new[] {
                Option<int>.None(),
                Option<int>.Some(10) };
            hoge
                .ForEach(opt => opt.
                    Match(
                        None: () => -1,
                        Some: v => v)
                    .Act(Console.WriteLine));

            //ConsList<T> = Variant<Unit,Tuple<T,ConsList<T>>>
            Console.WriteLine("\nConsList");
            var list = new[] { 2, 3, 5 , 8, 12 }.ToConsList();

            list
                .Match(
                    Nil: () => 0,
                    Cons: (head, tail) => head)
                .Act(Console.WriteLine);

            //Sum
            list
                .Catamorphism(
                    nil: () => 0,
                    cons: (h, t) => h + t)
                .Act(Console.WriteLine);

            Console.ReadLine();
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            string sample_sentence = "Find the 4 numbers in this string including 25 and 87 twice (a87test)";

            Regex r_ints   = new Regex("\d+");   // Match integers  (must add @ to front of string to fix error) --> @"\d+"
            Regex r_parens = new Regex("(");   // Match parens  (must add \ in front of '(' --> "\(" and then @ in front of string --> @"\("  )
            Match m = r_ints.Match(sample_sentence);

            Console.Write("All Numbers in String:\n");
            while (m.Success)
            {
                Console.WriteLine(m.Value);
                m = m.NextMatch();
            }

            Console.Write("\nParenthesis in String occur at:\n");

            m = r_parens.Match( sample_sentence );
            while (m.Success)
            {
                Console.WriteLine(m.Index);
                m = m.NextMatch();
            }

            Console.Write("\nMatch Spreadsheet Columns/Rows:\n");


            // Match spreadsheet cell names, extract column and row separately
            // Note the use of parentheses to capture pieces of a match
            r_ints = new Regex(@"([a-zA-Z]+)([1-9]\d*)");
            m = r_ints.Match("AA32 hello BC19AX22the end");
            while (m.Success)
            {
                Console.WriteLine("Row: " + m.Groups[1]);
                Console.WriteLine("Col: " + m.Groups[2]);
                m = m.NextMatch();
            }
            
            // Wait for termination
            Console.ReadLine();
        }
        private void ProcessRegex(string line, int lineStart, System.Text.RegularExpressions.Regex regexp, Color color)
        {
            if (regexp == null)
                return;

            System.Text.RegularExpressions.Match regMatch;

            for (regMatch = regexp.Match(line); regMatch.Success; regMatch = regMatch.NextMatch())
            {
                // Process the words
                int nStart = lineStart + regMatch.Index;
                int nLenght = regMatch.Length;
                SelectionStart = nStart;
                SelectionLength = nLenght;
                SelectionColor = color;
            }
        }
Exemple #4
0
        private void addfilesfromdirectory( System.IO.DirectoryInfo di,  System.Text.RegularExpressions.Regex regexfiles )
        {
            System.IO.FileInfo fi;
            System.IO.FileInfo[] fis;

            fis = di.GetFiles();
            //foreach( System.IO.FileInfo fi in di.GetFiles()) {
            for(int i = 0; i < fis.Length; i++) {
                fi = fis[i];
                if(regexfiles.Match(fi.Name).Success ) {
                    filetotal += 1;
                    strBuffer.Append(fi.Name + "\r\n");
                }
                //if( filetotal > 1024)
                //	break;
            }
        }