コード例 #1
0
        /// <summary>
        /// Parses the fetched content.
        /// </summary>
        protected override void parseContent()
        {
            // Initialize the scraper
            this.Translation = string.Empty;
            string       strContent = this.Content;
            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
        }
コード例 #2
0
        public static string removeComments(string strString)
        {
            string       text         = "";
            string       text2        = "";
            StringParser stringParser = new StringParser(strString);

            while (stringParser.extractTo("<!--", ref text2))
            {
                text += text2;
                if (!stringParser.skipToEndOf("-->"))
                {
                    return(strString);
                }
            }
            stringParser.extractToEnd(ref text2);
            return(text + text2);
        }
コード例 #3
0
            /// <summary>
            /// Parses the fetched content.
            /// </summary>
            protected override void parseContent()
            {
                // Initialize the scraper
                this.Translation = string.Empty;
                string strContent = this.Content;
                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
            }
コード例 #4
0
ファイル: StringParser.cs プロジェクト: vnkolt/NetOffice
 public static string removeComments(string strString)
 {
     string text = "";
     string text2 = "";
     StringParser stringParser = new StringParser(strString);
     while (stringParser.extractTo("<!--", ref text2))
     {
         text += text2;
         if (!stringParser.skipToEndOf("-->"))
         {
             return strString;
         }
     }
     stringParser.extractToEnd(ref text2);
     return text + text2;
 }