public async Task <dynamic> GetPhones03(string url = "http://www.rondonia.ro.gov.br/portal/contato/")
        {
            var config   = Configuration.Default.WithDefaultLoader();
            var context  = BrowsingContext.New(config);
            var document = await context.OpenAsync(url);

            var index = document.DocumentElement.OuterHtml.IndexOf("Telefone");
            var text  = document.DocumentElement.OuterHtml.Substring(index, 500);

            List <string> phones = new List <string>();

            while (text.Length > 0)
            {
                index = text.IndexOf("69"); // <-- temos a informação de que o DDD é 69

                if (index != -1)
                {
                    var phone = text.Substring(index, 12);
                    phone = StringManipulate.OnlyNumbers(phone);
                    phones.Add(phone);
                    index = index + 11;
                    text  = text.Substring(index, text.Length - index);
                }
                else
                {
                    break;
                }
            }

            return(phones);
        }
        public async Task <dynamic> GetPhones04(string url = "http://www.rondonia.ro.gov.br/portal/contato/")
        {
            var config   = Configuration.Default.WithDefaultLoader();
            var context  = BrowsingContext.New(config);
            var document = await context.OpenAsync(url);

            var index = document.DocumentElement.OuterHtml.IndexOf("Telefone");
            var text  = document.DocumentElement.OuterHtml.Substring(index, 500);

            var list = from r in text
                       .Split("<td style=\"text-align:right;width:100px\">")
                       select StringManipulate.OnlyNumbers(r);

            return(list);
        }
Пример #3
0
        static void Main(string[] args)
        {
            // make a string
            string input = "Hello C sharp world";

            /// <heading>Remove space character</heading>
            // make an object to implement the function
            StringManipulate rmSpaceChar = new StringManipulate();
            // make an empty string to receive a string without spaces
            string my_str = "";

            // remove the space then assign it
            my_str = rmSpaceChar.rmSpaceChar(input);

            /// <heading>Convert the all uppercase letter in the string into lowercase</heading>
            my_str = my_str.ToLower();

            /// <heading>Sort the string</heading>
            ArraySorting arrSort = new ArraySorting();

            // sort the array
            my_str = arrSort.SortArray(my_str);

            /// <heading>Calculate the frequency of character in the string</heading>
            // create an instance to implement the method to count the frequency
            Frequency freq = new Frequency();
            // make a dictionary
            Dictionary <char, int> my_dict = new Dictionary <char, int>();

            // initialize to the dictionary
            my_dict = freq.Frequency_of_char(my_str);

            // print out the dictionary, each key-value
            // make a KeyValuePair instance to access to the pair of values in Dictionary
            foreach (KeyValuePair <char, int> word in my_dict)
            {
                // Access the `Key` and `Value` field of the `word` instance
                Console.WriteLine("\'{0}\' : {1}", word.Key, word.Value);
            }
        }