diff --git a/HTMLParser.Example/Parsed.aspx.cs b/HTMLParser.Example/Parsed.aspx.cs index af9c477..aa8e6e7 100644 --- a/HTMLParser.Example/Parsed.aspx.cs +++ b/HTMLParser.Example/Parsed.aspx.cs @@ -21,8 +21,8 @@ namespace HTMLParser.Example ParserEx parse = new ParserEx(); this.ParsedUrl.InnerHtml = parse.ParseUrl(this.txtSource.Value); - this.parsedYoutube.InnerHtml = parse.GenerateYoutubeScripts(this.txtSource.Value).First(); - this.parsedUrlAndYoutube.InnerHtml = parse.GenerateYoutubeScripts(this.txtSource.Value).First() + parse.ParseUrl(this.txtSource.Value); + this.parsedYoutube.InnerHtml = parse.GenerateYoutubeScripts(this.txtSource.Value).FirstOrDefault() ?? ""; + this.parsedUrlAndYoutube.InnerHtml = parse.ParseUrlAndYoutube(this.txtSource.Value); } } } \ No newline at end of file diff --git a/HTMLParser/ParserEx.cs b/HTMLParser/ParserEx.cs index 0addcc3..98f40d4 100644 --- a/HTMLParser/ParserEx.cs +++ b/HTMLParser/ParserEx.cs @@ -59,7 +59,7 @@ namespace HTMLParser public List GenerateYoutubeScripts(string article) { - if (string.IsNullOrEmpty(article)) return null; + if (string.IsNullOrEmpty(article)) return new List(new string[] { "" }); Regex regex = new Regex(@"youtu(?:\.be|be\.com)/(?:.*v(?:/|=)|(?:.*/)?)([a-zA-Z0-9-_]+)"); Match match = regex.Match(article); @@ -75,7 +75,7 @@ namespace HTMLParser public string ParseUrlAndYoutube(string article) { - return this.GenerateYoutubeScripts(article).First() + this.ParseUrl(article); + return this.GenerateYoutubeScripts(article).FirstOrDefault() ?? "" + this.ParseUrl(article); } } }