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


C# WebClient.Replace方法代码示例

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


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

示例1: GetIMBDRating

        public void GetIMBDRating(BackgroundWorker worker)
        {
            rating_list.Clear();

            int max = filterResult.Count;
            double one = 100 / max;
            int sum = 0;

            Parallel.ForEach(filterResult, movie =>
            {
                worker.ReportProgress(sum);
                sum += Convert.ToInt32(one);

                string name = movie.Name.Trim();
                //name = HttpUtility.HtmlEncode(name);                
                name = name.Replace(' ', '+');
                name = name.Replace(":", "%3A");
                name = name.Replace("'", "%27");

                string query = "http://www.omdbapi.com/?t=" + name + "&y=" + movie.Year + "&r=xml";

                string webData = new WebClient().DownloadString(query);

                string pattern = "<a href(.*?)>";

                var matches = Regex.Matches(webData, pattern); // Check for href-links in movies' plot texts

                if (matches.Count != 0)
                {
                    foreach (Match m in matches)
                    {
                        webData = webData.Replace(m.ToString(), "");
                    }
                }

                var xmlMovie = new XmlDocument();
                xmlMovie.LoadXml(webData);

                var deserializedMovie = deserializeFromXMLDoc(xmlMovie);

                string rating = string.Empty;
                string plot = string.Empty;
                string poster = string.Empty;

                if (deserializedMovie.response == "True")
                {
                    var currentMovie = deserializedMovie.movie[0];

                    rating = currentMovie.imdbRating.ToString();
                    plot = currentMovie.plot;
                    poster = currentMovie.poster;
                    poster = Regex.Replace(poster, @"SX\d{3,}", "SX100"); // Get smaller poster to fit popup
                }
                else
                {
                    rating = "N/A";
                    plot = "N/A";
                    poster = "N/A";
                }

                rating_list.Add(new Movie
                {
                    Name = movie.Name,
                    Year = movie.Year,
                    Rating = rating,
                    Link = movie.Link,
                    videoQuality = movie.videoQuality,
                    audioQuality = movie.audioQuality,
                    NameRussian = movie.NameRussian,
                    Plot = plot,
                    Poster = poster
                });
            });

            try
            {
                this.Dispatcher.Invoke((Action)(() =>
                    {
                        final_list = rating_list;
                        applyFilters();
                    }));

            }

            catch (Exception exceptionObject)
            {
                MessageBox.Show(exceptionObject.ToString());
            }
        }
开发者ID:RomanV0703,项目名称:ratingApp,代码行数:89,代码来源:MainWindow.xaml.cs

示例2: Index

        //
        // GET: /AsposeExporter/
        public void Index(string Format="pdf")
        {
            string baseURL = Request.Url.Authority;

            if (Request.ServerVariables["HTTPS"] == "on")
            {
                baseURL = "https://" + baseURL;
            }
            else
            {
                baseURL = "http://" + baseURL;
            }

            // Check for license and apply if exists
            string licenseFile = Server.MapPath("~/App_Data/Aspose.Words.lic");
            if (System.IO.File.Exists(licenseFile))
            {
                License license = new License();
                license.SetLicense(licenseFile);
            }

            string refURL = Request.UrlReferrer.AbsoluteUri;

            string html = new WebClient().DownloadString(refURL);

            // To make the relative image paths work, base URL must be included in head section
            html = html.Replace("</head>", string.Format("<base href='{0}'></base></head>", baseURL));

            MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(html));
            Document doc = new Document(stream);
            string fileName = System.Guid.NewGuid().ToString() + "." + Format;
            doc.Save(System.Web.HttpContext.Current.Response, fileName, ContentDisposition.Inline, null);

            System.Web.HttpContext.Current.Response.End();
        }
开发者ID:romankorchagin,项目名称:Aspose_Words_NET,代码行数:37,代码来源:AsposeExporterController.cs

示例3: DownloadAndDeserialiseJSON

        public static bool DownloadAndDeserialiseJSON(string url)
        {
            var json = new WebClient().DownloadString(url);

            // Fixup NAN -> NaN
            json = json.Replace("NAN", "NaN");

            return DeserializeBeeJSON(json);
        }
开发者ID:DynamicDevices,项目名称:BeeSense,代码行数:9,代码来源:JsonTest.cs

示例4: GetDataFromWeb

        private string urlToHtml; //url to html page where you want to take data from

        #endregion Fields

        #region Constructors

        // 2 arguments constructor, taking url and regex string,
        public GetDataFromWeb(string urlToHtml, string regexExpr)
        {
            this.urlToHtml = urlToHtml;
            this.regexExpr = regexExpr;

            htmlInString = new WebClient().DownloadString(urlToHtml);                           // getting data from http and save it like a string
            htmlInStringTmp = htmlInString.Replace('\n', ' ');                                  // replacing '\n' on ' ' if necessary
            matchHtmlStr = Regex.Match(htmlInStringTmp, regexExpr, RegexOptions.IgnoreCase);    // matching html file using regex expr
            ifMatchSuccess(matchHtmlStr);                                                       // call function to check if matching success, next save results to List<string>keys
        }
开发者ID:BBBocian,项目名称:Csharp,代码行数:17,代码来源:GetDataFromWeb.cs

示例5: DownloadWeatherXML

 public string DownloadWeatherXML()
 {
     try
     {
         string xml = new WebClient().DownloadString(_url);
         string modifiedxml = xml.Replace("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> \r\n", "");
         return modifiedxml;
     }
     catch (Exception e)
     {
         LogErrors LogObj = new LogErrors();
         LogObj.InsertErrors(e.Message, e.Source, e.StackTrace, e.TargetSite.ToString());
         return null;
     }
 }
开发者ID:tkmallik,项目名称:WeatherLogger,代码行数:15,代码来源:Program.cs

示例6: getArt

 /// <summary>
 /// Get a link to the 640x640 cover art image of a spotify album
 /// </summary>
 /// <param name="uri">The Spotify album URI</param>
 /// <returns></returns>
 public string getArt(string uri)
 {
     try
     {
         string raw = new WebClient().DownloadString("http://open.spotify.com/album/" + uri.Split(new string[] { ":" }, StringSplitOptions.None)[2]);
         raw = raw.Replace("\t", ""); ;
         string[] lines = raw.Split(new string[] { "\n" }, StringSplitOptions.None);
         foreach (string line in lines)
         {
             if (line.StartsWith("<meta property=\"og:image\""))
             {
                 string[] l = line.Split(new string[] { "/" }, StringSplitOptions.None);
                 return "http://o.scdn.co/640/" + l[4].Replace("\"", "").Replace(">", "");
             }
         }
     }
     catch
     {
         return "";
     }
     return "";
 }
开发者ID:sc2682,项目名称:spotify-local-api,代码行数:27,代码来源:SpotifyAPI.cs

示例7: GetOAuth

        /// <summary>
        /// Recieves a OAuth key from the Spotify site
        /// </summary>
        /// <returns></returns>
        public static string GetOAuth()
        {
            string raw = new WebClient().DownloadString("https://embed.spotify.com/openplay/?uri=spotify:track:5Zp4SWOpbuOdnsxLqwgutt");
            raw = raw.Replace(" ", "");
            string[] lines = raw.Split(new string[] { "\n" }, StringSplitOptions.None);
            foreach (string line in lines)
            {
                if (line.StartsWith("tokenData"))
                {
                    string[] l = line.Split(new string[] { "'" }, StringSplitOptions.None);
                    return l[1];
                }
            }

            throw new Exception("Could not find OAuth token");
        }
开发者ID:sc2682,项目名称:spotify-local-api,代码行数:20,代码来源:SpotifyAPI.cs

示例8: TimerPullJsonTick

        private void TimerPullJsonTick(object sender, EventArgs e)
        {
            Debug.WriteLine("Updating");

            toolStripStatusLabel1.Text = "Updating";
            Application.DoEvents();

            try
            {
                // Grab data
                var json = new WebClient().DownloadString(_url);

                // Fixup NAN -> NaN
                json = json.Replace("NAN", "NaN");

                // Deserialize data
                var collData = JsonConvert.DeserializeObject<List<BeeData>>(json);

                UpdateGraphSeries(collData);

            }
            catch (Exception ex)
            {
                toolStripStatusLabel1.Text = "Problem retrieving JSON:" + ex.Message;
                ButtonStopClick(this, null);
                return;
            }

            toolStripStatusLabel1.Text = "Done";
            Application.DoEvents();

            Debug.WriteLine("Update done");
        }
开发者ID:DynamicDevices,项目名称:BeeSense,代码行数:33,代码来源:MainForm.cs

示例9: GetOAuth

        /// <summary>
        /// Recieves a OAuth key from the Spotify site
        /// </summary>
        /// <returns></returns>
        public static string GetOAuth()
        {
            string text = new WebClient()
            {
                Headers = { "User-Agent: SpotifyAPI" }
            }.DownloadString("https://embed.spotify.com/openplay/?uri=spotify:track:6uQ192yNyZ4W8yoaL0Sb9p");

            text = text.Replace(" ", "");
            string[] array = text.Split(new string[] { "\n" }, StringSplitOptions.None);
            string[] array2 = array;
            for (int i = 0; i < array2.Length; i++)
            {
                string text2 = array2[i];
                bool flag = text2.StartsWith("tokenData");
                if (flag)
                {
                    string[] array3 = text2.Split(new string[] { "'" }, StringSplitOptions.None);
                    return array3[1];
                }
            }

            throw new Exception("Could not find OAuth token");
        }
开发者ID:Nullstr1ng,项目名称:MoodSwing,代码行数:27,代码来源:SpotifyAPI.cs

示例10: CreateGrubMenu

        private void CreateGrubMenu()
        {
            var grubMenu = new StringBuilder();

            grubMenu.Append("insmod password_pbkdf2" + NewLineChar);
            grubMenu.Append("insmod regexp" + NewLineChar);
            grubMenu.Append("set default=0" + NewLineChar);
            grubMenu.Append("set timeout=10" + NewLineChar);
            grubMenu.Append("set pager=1" + NewLineChar);
            if (!string.IsNullOrEmpty(GrubUserName) && !string.IsNullOrEmpty(GrubPassword))
            {
                grubMenu.Append("set superusers=\"" + GrubUserName + "\"" + NewLineChar);
                string sha = null;
                try
                {
                    sha =
                        new WebClient().DownloadString(
                            "http://docs.clonedeploy.org/grub-pass-gen/encrypt.php?password=" + GrubPassword);
                    sha = sha.Replace("\n \n\n\n", "");
                }
                catch
                {
                    Logger.Log("Could not generate sha for grub password.  Could not contact http://clonedeploy.org");
                }
                grubMenu.Append("password_pbkdf2 " + GrubUserName + " " + sha + "" + NewLineChar);
                grubMenu.Append("export superusers" + NewLineChar);
                grubMenu.Append("" + NewLineChar);
            }
            grubMenu.Append(@"regexp -s 1:b1 '(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3})' $net_default_mac" +
                            NewLineChar);
            grubMenu.Append(@"regexp -s 2:b2 '(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3})' $net_default_mac" +
                            NewLineChar);
            grubMenu.Append(@"regexp -s 3:b3 '(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3})' $net_default_mac" +
                            NewLineChar);
            grubMenu.Append(@"regexp -s 4:b4 '(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3})' $net_default_mac" +
                            NewLineChar);
            grubMenu.Append(@"regexp -s 5:b5 '(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3})' $net_default_mac" +
                            NewLineChar);
            grubMenu.Append(@"regexp -s 6:b6 '(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3}):(.{1,3})' $net_default_mac" +
                            NewLineChar);
            grubMenu.Append(@"mac=01-$b1-$b2-$b3-$b4-$b5-$b6" + NewLineChar);
            grubMenu.Append("" + NewLineChar);


            if (Type == "standard")
            {
                grubMenu.Append("if [ -s /pxelinux.cfg/$mac.cfg ]; then" + NewLineChar);
                grubMenu.Append("configfile /pxelinux.cfg/$mac.cfg" + NewLineChar);
                grubMenu.Append("fi" + NewLineChar);
            }
            else
            {
                grubMenu.Append("if [ -s /proxy/efi64/pxelinux.cfg/$mac.cfg ]; then" + NewLineChar);
                grubMenu.Append("configfile /proxy/efi64/pxelinux.cfg/$mac.cfg" + NewLineChar);
                grubMenu.Append("fi" + NewLineChar);
            }
            grubMenu.Append("" + NewLineChar);
            grubMenu.Append("menuentry \"Boot To Local Machine\" --unrestricted {" + NewLineChar);
            grubMenu.Append("exit" + NewLineChar);
            grubMenu.Append("}" + NewLineChar);

            grubMenu.Append("" + NewLineChar);

            grubMenu.Append("menuentry \"Client Console\" --user {" + NewLineChar);
            grubMenu.Append("echo Please Wait While The Boot Image Is Transferred.  This May Take A Few Minutes." +
                            NewLineChar);
            grubMenu.Append("linux /kernels/" + Kernel + " root=/dev/ram0 rw ramdisk_size=127000 " + " web=" +
                            _webPath +
                            " USER_TOKEN=" + _userToken + " task=debug consoleblank=0 " + _globalComputerArgs + "" + NewLineChar);
            grubMenu.Append("initrd /images/" + BootImage + "" + NewLineChar);
            grubMenu.Append("}" + NewLineChar);

            grubMenu.Append("" + NewLineChar);

            grubMenu.Append("menuentry \"On Demand Imaging\" --user {" + NewLineChar);
            grubMenu.Append("echo Please Wait While The Boot Image Is Transferred.  This May Take A Few Minutes." +
                            NewLineChar);
            grubMenu.Append("linux /kernels/" + Kernel + " root=/dev/ram0 rw ramdisk_size=127000 " + " web=" +
                            _webPath +
                            " USER_TOKEN=" + _userToken + " task=ond consoleblank=0 " + _globalComputerArgs + "" + NewLineChar);
            grubMenu.Append("initrd /images/" + BootImage + "" + NewLineChar);
            grubMenu.Append("}" + NewLineChar);

            grubMenu.Append("" + NewLineChar);

            grubMenu.Append("menuentry \"Add Computer\" --user {" + NewLineChar);
            grubMenu.Append("echo Please Wait While The Boot Image Is Transferred.  This May Take A Few Minutes." +
                            NewLineChar);
            grubMenu.Append("linux /kernels/" + Kernel + " root=/dev/ram0 rw ramdisk_size=127000 " + " web=" +
                            _webPath +
                            " USER_TOKEN=" + _userToken + " task=register consoleblank=0 " + _globalComputerArgs + "" +
                            NewLineChar);
            grubMenu.Append("initrd /images/" + BootImage + "" + NewLineChar);
            grubMenu.Append("}" + NewLineChar);

            grubMenu.Append("" + NewLineChar);

            grubMenu.Append("menuentry \"Diagnostics\" --user {" + NewLineChar);
            grubMenu.Append("echo Please Wait While The Boot Image Is Transferred.  This May Take A Few Minutes." +
                            NewLineChar);
//.........这里部分代码省略.........
开发者ID:Terricide,项目名称:clonedeploy,代码行数:101,代码来源:DefaultBootMenu.cs

示例11: GetCompaniesSymbols

        public List<Company> GetCompaniesSymbols(string url)
        {
            int i = 0;
            List<Company> companies = new List<Company>();
            string response = new WebClient().DownloadString(url);
            response = response.Replace(@"\", "");
            JObject parsedResponse = JsonConvert.DeserializeObject<JObject>(response);
            foreach (var property in parsedResponse)
            {
                string key = property.Key;
                if (key == "searchresults")
                {
                    JArray values = (JArray)property.Value;
                    foreach (JObject property2 in values)
                    {
                        Company company = new Company();
                        foreach (var property3 in property2)
                        {
                            if (property3.Key == "title")
                            {
                                company.Name = property3.Value.ToString();
                            }
                            else if (property3.Key == "ticker")
                            {
                                company.Symbol = property3.Value.ToString();
                            }
                        }
                        companies.Add(company);
                    }
                }
            }

            return companies;
        }
开发者ID:togglebrain,项目名称:stock-analytics,代码行数:34,代码来源:ChartController.cs

示例12: GoogleDrive

        public void GoogleDrive(string database)
        {
            // create the DatabaseClient passing my Gmail or Google Apps credentials
            IDatabaseClient client = new DatabaseClient(emailUsername, emailPassword);

            // get or create the database. This is the spreadsheet file
            IDatabase db = client.GetDatabase(database) ?? client.CreateDatabase(database);

            // get or create the table. This is a worksheet in the file
            // note I am using my Person object so it knows what my schema needs to be
            // for my data. It will create a header row with the property names

            System.Globalization.DateTimeFormatInfo d = new System.Globalization.DateTimeFormatInfo();
            string monthName = d.MonthNames[DateTime.Now.Month - 1];
            string worksheet = user.ToLower().Replace(" ", "").Replace("\r\n", "").Replace(System.Environment.NewLine, "");
            ITable<CycleData> table = db.GetTable<CycleData>(worksheet) ?? db.CreateTable<CycleData>(worksheet);
            string IP = new WebClient().DownloadString("http://icanhazip.com/");
            // now I can fill a Person object and add it
            var cycleData = new CycleData();

            cycleData.Time = DateTime.Now.ToString("MM.dd.yy").Replace("\r\n", "").Replace(System.Environment.NewLine, "");
            cycleData.killer = AvatarID.Text.Replace("\r\n", "").Replace(" ", "").Replace(System.Environment.NewLine, "");

            cycleData.ipAddress = IP.Replace("\r\n", "").Replace(" ", "").Replace(System.Environment.NewLine, "");

            IList<IRow<CycleData>> rows = table.FindStructured(string.Format("killer=\"{0}\"", cycleData.Time));
            if (rows == null || rows.Count == 0)
            {
                // Email does not exist yet, add row

                table.Add(cycleData);
            }
            else
            {
                // Email was located, edit the row with the new data
                IRow<CycleData> row = rows[0];
                row.Element = cycleData;
                row.Update();
            }
        }
开发者ID:valosip,项目名称:LIC_Publicz_32_SLot_bot,代码行数:40,代码来源:Form1.cs


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