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


C# StringParser.skipToEndOf方法代码示例

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


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

示例1: parseContent

        /**
         * Parses and saves the content
         * */
        private void parseContent()
        {
            try
            {
                //Declare variables
                String contentToParse = String.Empty;
                String langToParse = String.Empty;
                List<Language> languages = new List<Language>();
                StringParser sp = new StringParser(this.Content);

                //Do the parsing
                sp.skipToEndOf("&#8212;</option>");
                sp.extractTo("</select>", ref contentToParse);
                String[] separations = { "</option>", "<option ", "value=" };
                String[] options = contentToParse.ToString().Split(separations, System.StringSplitOptions.RemoveEmptyEntries);
                options = options.Except(new List<string>() { "SELECTED " }).ToArray<string>();

                //Get languages
                languages = (from lang in options
                             select new Language
                             {
                                 code = lang.ToString().Split('>')[0].ToString(),
                                 name = lang.ToString().Split('>')[1].ToString()
                             }).ToList<Language>();

                //Write over current languages in settings and save them to file
                Settings.set.languages = languages.ToArray();
                Settings.SaveSettings();
            }
            catch (ArgumentNullException ae)
            {
                Logger.log.Error("Couldn't create language object from fetched data", ae);
                throw new Exception("Couldn't create language object from fetched data. See log for more information");
            }
            catch (Exception e)
            {
                Logger.log.Error("Exception occured", e);
                throw new Exception("Exception occured. See log for more information");
            }
        }
开发者ID:viebke,项目名称:TranslateOnTheFly,代码行数:43,代码来源:Updater.cs

示例2: parseContent

        /// <summary>
        /// Parses the fetched content.
        /// </summary>
        protected override void parseContent()
        {
            try
            {
                // Initialize the scraper
                this.Translation = string.Empty;
                string strContent = this.data;
                StringParser parser = new StringParser(strContent);

                // Scrape the translation
                string strTranslation = string.Empty;
                if (parser.skipToEndOf("<span id=result_box"))
                {
                    if (parser.skipToEndOf("onmouseout=\"this.style.backgroundColor='#fff'\">"))
                    {
                        if (parser.extractTo("</span>", ref strTranslation))
                        {
                            strTranslation = StringParser.removeHtml(strTranslation);
                        }
                    }
                }

                #region Fix up the translation
                int startClean = 0;
                int endClean = 0;
                int i = 0;
                while (i < strTranslation.Length)
                {
                    if (Char.IsLetterOrDigit(strTranslation[i]))
                    {
                        startClean = i;
                        break;
                    }
                    i++;
                }
                i = strTranslation.Length - 1;
                while (i > 0)
                {
                    char ch = strTranslation[i];
                    if (Char.IsLetterOrDigit(ch) ||
                        (Char.IsPunctuation(ch) && (ch != '\"')))
                    {
                        endClean = i;
                        break;
                    }
                    i--;
                }

                this.Translation = strTranslation.Substring(startClean, endClean - startClean + 1).Replace("\"", "");
                #endregion
            }
            catch (Exception e)
            {
                Logger.log.Error("Exception occured while parsing data", e);
                throw new Exception("Unable to parse content: " + e.Message);
            }
        }
开发者ID:viebke,项目名称:TranslateOnTheFly,代码行数:60,代码来源:Translator.cs


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