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


C# HttpClient.Substring方法代码示例

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


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

示例1: LoadProblemRankings

 public static ProblemRanking[] LoadProblemRankings()
 {
     var s = new HttpClient().GetStringAsync("https://davar.icfpcontest.org/rankings.js").Result;
     JObject v = (JObject)JsonConvert.DeserializeObject(s.Substring(11));
     var problems = v["data"]["settings"].ToObject<ProblemRanking[]>();
     return problems;
 }
开发者ID:xoposhiy,项目名称:icfpc2015,代码行数:7,代码来源:Scoreboard.cs

示例2: GetAmazonProductPrice

        // Amazon UK price history can be checked in uk.camelcamelcamel.com, for example: http://uk.camelcamelcamel.com/Sennheiser-Professional-blocking-gaming-headset-Black/product/B00JQDOANK
        private static double? GetAmazonProductPrice(string p_amazonProductUrl)
        {
            string errorMessage = String.Empty;
            double price = 0.0;
            var webpage = new HttpClient().GetStringAsync(p_amazonProductUrl).Result;
            Utils.Logger.Info("HttpClient().GetStringAsync returned: " + ((webpage.Length > 100) ? webpage.Substring(0, 100) : webpage));

            // <span id="priceblock_ourprice" class="a-size-medium a-color-price">£199.95</span>
            string searchStr = @"id=""priceblock_ourprice"" class=""a-size-medium a-color-price"">";
            int startInd = webpage.IndexOf(searchStr);
            if (startInd == -1)
            {   // it is expected (not an exception), that sometimes Amazon changes its website, so we will fail. User will be notified.
                Utils.Logger.Info($"searchString '{searchStr}' was not found.");
                return null;
            }
            int endInd = webpage.IndexOf('<', startInd + searchStr.Length);
            if (endInd == -1)
            {   // it is expected (not an exception), that sometimes Amazon changes its website, so we will fail. User will be notified.
                Utils.Logger.Info($"'<' after searchString '{searchStr}' was not found.");
                return null;
            }
            string priceStr = webpage.Substring(startInd + searchStr.Length + 1, endInd - (startInd + searchStr.Length + 1));
            if (!Double.TryParse(priceStr, out price))
            {
                Utils.Logger.Info($"{priceStr} cannot be parsed to Double.");
                return null;
            }
            return price;
        }
开发者ID:gyantal,项目名称:SQLab,代码行数:30,代码来源:Controller.cs


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