本文整理汇总了C#中StringParser.extractTo方法的典型用法代码示例。如果您正苦于以下问题:C# StringParser.extractTo方法的具体用法?C# StringParser.extractTo怎么用?C# StringParser.extractTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringParser
的用法示例。
在下文中一共展示了StringParser.extractTo方法的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("—</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");
}
}
示例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);
}
}