From 0396443a51ddff731d64100096e71796389723c8 Mon Sep 17 00:00:00 2001 From: wook Date: Wed, 10 May 2017 14:30:34 +0900 Subject: [PATCH] Null Case --- HTMLParser.Example/Parsed.aspx.cs | 4 ++-- HTMLParser/ParserEx.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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); } } }