本文整理汇总了C#中System.Net.WebClient.Substring方法的典型用法代码示例。如果您正苦于以下问题:C# WebClient.Substring方法的具体用法?C# WebClient.Substring怎么用?C# WebClient.Substring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebClient
的用法示例。
在下文中一共展示了WebClient.Substring方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProBuilds
public ProBuilds(String champ)
{
Builds = new List<Build>();
String htmlPage = new WebClient().DownloadString("http://lolbuilder.net/" + champ);
foreach (Match buildsRegex in new Regex("#(build\\-[0-9]+)\">([a-zA-Z ]+) \\(<span class=\"hover-text\" tooltip=\"Seen in up to ([0-9]+)").Matches(htmlPage))
{
Build build = new Build();
Match buildRegex = new Regex(buildsRegex.Groups[1].ToString()).Matches(htmlPage)[1];
String buildSectionHtml = htmlPage.Substring(buildRegex.Index);
String summaryHtml = buildSectionHtml.Substring(buildSectionHtml.IndexOf("build-summary-separator separator"));
summaryHtml = summaryHtml.Substring(0, summaryHtml.IndexOf("build-box starting-items"));
String startingHtml = buildSectionHtml.Substring(buildSectionHtml.IndexOf("build-box starting-items"));
startingHtml = startingHtml.Substring(0, startingHtml.IndexOf("build-box early-game"));
String orderHtml = buildSectionHtml.Substring(buildSectionHtml.IndexOf("build-box early-game"));
orderHtml = orderHtml.Substring(0, orderHtml.IndexOf("build-box final-items"));
String finalHtml = buildSectionHtml.Substring(buildSectionHtml.IndexOf("build-box final-items"));
if (finalHtml.IndexOf("build-app-text") > 0)
finalHtml = finalHtml.Substring(0, finalHtml.IndexOf("build-app-text"));
build.Name = buildsRegex.Groups[2].ToString();
build.Popularity = buildsRegex.Groups[3].ToString();
build.Summary = GetItemsFromHtml(summaryHtml);
build.StartingItems = GetItemsFromHtml(startingHtml);
build.Order = GetItemsFromHtml(orderHtml);
build.BestItems = GetItemsFromHtml(finalHtml);
Builds.Add(build);
}
}
示例2: MainTextFetcher
public MainTextFetcher(string URL, string startingEnclosure, string endingEnclosure)
{
//Download the HTML code from given URL
string fetchedHTML = new WebClient().DownloadString(URL).ToString();
//Search for the first occurance of first tag
int firstPos = fetchedHTML.IndexOf(startingEnclosure);
int secondPos = fetchedHTML.IndexOf(endingEnclosure, firstPos);
//Fetch only the text of interest
mainText = fetchedHTML.Substring(firstPos + startingEnclosure.Length, secondPos - firstPos - startingEnclosure.Length);
}
示例3: MainTextFetcher
/// <summary>
/// Fetches text from a website and gets only the text between the two Tags.
/// </summary>
/// <param name="URL">Website URL (with HTTP)</param>
/// <param name="startingEnclosure">Starting Tag</param>
/// <param name="endingEnclosure">Stop Tag</param>
/// <returns></returns>
public string MainTextFetcher(string URL, string startingEnclosure, string endingEnclosure)
{
//Download the HTML code from given URL
string fetchedHTML = new WebClient().DownloadString(URL).ToString();
//Search for the first occurance of first tag
int firstPos = fetchedHTML.IndexOf(startingEnclosure);
if (firstPos < 0) { Console.WriteLine("Main text fetch failed (1)."); return ""; }
int secondPos = fetchedHTML.IndexOf(endingEnclosure, firstPos);
if (secondPos < 0) { Console.WriteLine("Main text fetch failed (2)."); return ""; }
//Fetch only the text of interest
return fetchedHTML.Substring(firstPos + startingEnclosure.Length, secondPos - firstPos - startingEnclosure.Length);
}
示例4: GetSpecInfo
static void GetSpecInfo()
{
String GameInfo = new WebClient().DownloadString(BaseUrl + RegionTag + UrlPartial + ObjectManager.Player.Name);
GameInfo = GameInfo.Substring(GameInfo.IndexOf(SearchString) + SearchString.Length);
GameInfo = GameInfo.Substring(GameInfo.IndexOf(" ") + 1);
Key = GameInfo.Substring(0, GameInfo.IndexOf(" "));
GameInfo = GameInfo.Substring(GameInfo.IndexOf(" ") + 1);
GameId = GameInfo.Substring(0, GameInfo.IndexOf(" "));
GameInfo = GameInfo.Substring(GameInfo.IndexOf(" ") + 1);
PlatformId = GameInfo.Substring(0, GameInfo.IndexOf(" "));
}
示例5: Index
public ActionResult Index(string folderPath, string url) {
var viewModel = new OEmbedViewModel {
Url = url,
FolderPath = folderPath
};
try {
// <link rel="alternate" href="http://vimeo.com/api/oembed.xml?url=http%3A%2F%2Fvimeo.com%2F23608259" type="text/xml+oembed">
var source = new WebClient().DownloadString(url);
// seek type="text/xml+oembed" or application/xml+oembed
var oembedSignature = source.IndexOf("type=\"text/xml+oembed\"", StringComparison.OrdinalIgnoreCase);
if (oembedSignature == -1) {
oembedSignature = source.IndexOf("type=\"application/xml+oembed\"", StringComparison.OrdinalIgnoreCase);
}
if (oembedSignature != -1) {
var tagStart = source.Substring(0, oembedSignature).LastIndexOf('<');
var tagEnd = source.IndexOf('>', oembedSignature);
var tag = source.Substring(tagStart, tagEnd - tagStart);
var matches = new Regex("href=\"([^\"]+)\"").Matches(tag);
if (matches.Count > 0) {
var href = matches[0].Groups[1].Value;
try {
var content = new WebClient().DownloadString(Server.HtmlDecode(href));
viewModel.Content = XDocument.Parse(content);
}
catch {
// bubble exception
}
}
}
}
catch {
return View(viewModel);
}
return View(viewModel);
}
示例6: getExternalIpAddress
} // end method
/// <summary>
/// Retrieve the external IP address via web request.
/// </summary>
private string getExternalIpAddress()
{
try
{
string jsonResponse = new WebClient().DownloadString(ipCheckUrl_m);
jsonResponse = jsonResponse.Split(':')[1].Replace('"', ' ').Trim();
return jsonResponse.Substring(0, jsonResponse.Length - 1).Trim();
}
catch (Exception)
{
return null;
} // end try-catch
} // end method
示例7: CheckForInternetConnection
private bool CheckForInternetConnection()
{
try
{
string str = new WebClient().DownloadString("http://labpp.org/check/internet/connection/");
int posStart = str.IndexOf("PublicIP\":\"") + 11;
int posEnd = str.IndexOf("\"}]");
string newIP = str.Substring(posStart, posEnd - posStart);
return true;
}
catch
{
return false;
}
}
示例8: Robots
public Robots(string authority)
{
string robotsTXTURL = authority + "/robots.txt";
content = new WebClient().DownloadString(robotsTXTURL);
int index = content.IndexOf("User-agent: *");
if (index >= 0)
{
string disallowedContent = content.Substring(index);
foreach (Match match in Regex.Matches(disallowedContent, @"Disallow:\s*([/-_.A-Za-z0-9]+)"))
{
disallowed.Add(Urls.BuildAbsUrl(robotsTXTURL, match.Groups[1].Value));
}
}
excludeUrlsWithoutToken = "";
}
示例9: FindName
public string FindName()
{
var response = new WebClient().DownloadString("http://example.com/");
var prefix = "Hello, ";
var suffix = "!";
if (!response.StartsWith(prefix))
{
throw new NotImplementedException("The beginning of the response is invalid.");
}
if (!response.EndsWith(suffix))
{
throw new NotImplementedException("The ending of the response is invalid.");
}
return response.Substring(prefix.Length, response.Length - prefix.Length - suffix.Length);
}
示例10: ConvertFromTo
public static Decimal ConvertFromTo(string fromCurrency, string toCurrency)
{
if (!AllSymbols().Contains(fromCurrency))
throw new CurrencyDoesNotExistException(fromCurrency);
if (!AllSymbols().Contains(toCurrency))
throw new CurrencyDoesNotExistException(toCurrency);
var url = String.Format(
"http://www.gocurrency.com/v2/dorate.php?"
+ "inV=1&from={0}&to={1}&Calculate=Convert",
fromCurrency, toCurrency);
var client = new WebClient();
var result = new WebClient().DownloadString(url);
var index = result.IndexOf("<div id=\"converter_results\"><ul><li>");
var theGoodStuff = result.Substring(index);
var startIndex = theGoodStuff.IndexOf("<b>") + 3;
var endIndex = theGoodStuff.IndexOf("</b>");
var importantStuff = theGoodStuff.Substring(startIndex, endIndex - startIndex);
var parts = importantStuff.Split('=');
var almostValue = parts[1].Trim().Split(' ')[0];
return Decimal.Parse(almostValue, new CultureInfo("en"));
}
示例11: GetForecast
public static Report[] GetForecast(string location, string language, bool metric, int nDays, bool hourly)
{
string url;
if (!hourly)
url = constructWeathermapURL("http://api.openweathermap.org/data/2.5/forecast/daily?q=", location, language, metric, nDays);
else
url = constructWeathermapURL("http://api.openweathermap.org/data/2.5/forecast?q=", location, language, metric, 0);
string resp = new WebClient().DownloadString(url);
resp = resp.Substring(resp.IndexOf("\"list\":[{") + 9);
string[] segments = resp.Split(new string[] { "},{" }, StringSplitOptions.RemoveEmptyEntries);
int n = segments.Length;
if (hourly)
n = Math.Min(n, 8 * nDays + 1);
Report[] reports = new Report[n];
for (int i = 0; i < n; i++)
reports[i] = buildReport(segments[i], hourly, metric);
return reports;
}
示例12: GetWebcamImage
public static string GetWebcamImage(string webcamsTravelURL)
{
try
{
string page = new WebClient().DownloadString(webcamsTravelURL);
int lb = page.IndexOf("http://images.webcams.travel/thumbnail/");
if (lb == -1)
return "";
else
{
int ub = page.IndexOf('"', lb);
if (ub == -1)
return "";
else
return page.Substring(lb, ub - lb).Replace("/thumbnail/", "/webcam/");
}
}
catch (Exception exc)
{
Exception = exc;
return "";
}
}
示例13: Wallhaven
private static string Wallhaven(string url)
{
if (Regex.IsMatch(url, @"http://alpha.wallhaven.cc/wallpaper/\d+"))
{
string contents = new WebClient().DownloadString(url);
int index = contents.IndexOf(@"content=""//", StringComparison.Ordinal);
if (index != -1)
{
index += 9;
return "http:" + contents.Substring(index,
contents.IndexOf(@"""", index, StringComparison.Ordinal) - index);
}
throw new Exception("Perhaps wallhaven changed their html pages?");
}
return url;
}
示例14: getRDWData
private void getRDWData(string plate)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
var json = new WebClient().DownloadString(
String.Format("https://opendata.rdw.nl/resource/m9d7-ebf2.json?$$App_Token=ZLpdTpUjHwrZqSC85a6tu6TSl&kenteken={0}", plate));
if (json.Length > 5) {
json = json.Substring(1, json.Length - 3);
var dict = serializer.Deserialize<Dictionary<String, String>>(json);
string merk = "";
if (dict.ContainsKey("voertuigsoort")) {
if (dict["voertuigsoort"].ToLower() == "bromfiets" && dict.ContainsKey("merk")) {
merk = dict["merk"];
}
}
this.brandSelection.Text = merk;
}
}
示例15: SubmitCaptchaAsyncDoWork
private void SubmitCaptchaAsyncDoWork(object sender, DoWorkEventArgs e)
{
CSubmitCaptchaData argument = (CSubmitCaptchaData)e.Argument;
string url = argument.url;
DateTime tm = argument.tm;
string str = "";
try
{
str = new WebClient().DownloadString(url);
}
catch (Exception)
{
return;
}
if (str.IndexOf("Your answer was correct.") != -1 || str.IndexOf("Réponse correcte") != -1)//Add || and your local language here.
{
uint index = (uint)str.IndexOf("cols=\"100\">");
uint num2 = (uint)str.IndexOf("<", (int)(((int)index) + 1));
captchas.Add(new CCaptcha(str.Substring(((int)index) + 11, ((int)(num2 - index)) - 11), tm));
}
}