{"id":177,"date":"2009-04-17T12:07:00","date_gmt":"2009-04-17T16:07:00","guid":{"rendered":"http:\/\/madprogrammer76.wordpress.com\/2009\/04\/17\/how-would-you-split-with-c"},"modified":"2013-12-18T15:44:20","modified_gmt":"2013-12-18T20:44:20","slug":"how-would-you-split-with-c","status":"publish","type":"post","link":"http:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/","title":{"rendered":"How would you split with C-Sharp"},"content":{"rendered":"<p>How would you split a string with comma separated values and remove any blank records?<\/p>\n<p>While the solution may seem obvious to most folks, it is not always obvious to everyone. I have been asking perspective candidates this question, but there is one common answer that I get.<\/p>\n<blockquote style=\"color: #990000;\"><p>&#8220;Create a loop with two array variables. Loop through the comma separated string and do substring to extract each value while keeping the current index to use as your next starting point. Then create another loop to loop through your new array of strings to add the strings with length greater than zero to a new array&#8230; then return your newest array of strings.&#8221;<\/p><\/blockquote>\n<p>That seems like a lot of loops, a lot of string arrays and a lot of thinking.<\/p>\n<p>Whenever I suggest using the String object&#8217;s <span style=\"color: #6666cc;\">split <\/span>command using the <span style=\"color: #6666cc;\">RemoveEmptyEntries<span style=\"color: black;\">; I get told &#8220;<span style=\"color: #cc0000;\">Oh, what I told you is probably what DotNet is doing under the hood<\/span>&#8220;<\/span><\/span>.<\/p>\n<p>My god, that seems like a lot of work even for DotNet. I urge everyone to look at the functions available before undertaking such routines. Can you imagine the code that would be produced by a developer who is always writing code like described above? If you are unsure, use google to find your answer or even better yet use MSDN. Do not assume you know everything, because you are not expected to. There are resources around&#8230; Internet is a developer&#8217;s best friend.<\/p>\n<p><span style=\"font-weight: bold;\">Source for String Split Options:<\/span> <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms131448.aspx\">http:\/\/msdn.microsoft.com\/en-us\/library\/ms1314<\/a><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms131448.aspx\">48.aspx<\/a><\/p>\n<p><span style=\"font-weight: bold;\">Sample Google Query used t<\/span><img decoding=\"async\" alt=\"\" src=\"\/Users\/apallant\/AppData\/Local\/Temp\/moz-screenshot-1.jpg\" \/><span style=\"font-weight: bold;\">o find the answers:<\/span><a style=\"font-weight: bold;\" href=\"http:\/\/www.unlatched.com\/blog\/uploaded_images\/Untitled-716505.jpg\"><img decoding=\"async\" alt=\"\" src=\"http:\/\/www.unlatched.com\/blog\/uploaded_images\/Untitled-716504.jpg\" border=\"0\" \/><\/a><br \/>\n<img decoding=\"async\" alt=\"\" src=\"\/Users\/apallant\/AppData\/Local\/Temp\/moz-screenshot.jpg\" \/><\/p>\n<div class=\"blogger-post-footer\"><img alt=\"\" width=\"1\" height=\"1\" \/><\/div>\n","protected":false},"excerpt":{"rendered":"<p>How would you split a string with comma separated values and remove any blank records? While the solution may seem obvious to most folks, it is not always obvious to everyone. I have been asking perspective candidates this question, but there is one common answer that I get. &#8220;Create a loop with two array variables. &hellip; <a href=\"http:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">How would you split with C-Sharp<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[39],"tags":[162],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\r\n<title>How would you split with C-Sharp - LDNDeveloper<\/title>\r\n<meta name=\"description\" content=\"How would you split with C-Sharp - an interview question.\" \/>\r\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/\" \/>\r\n<meta property=\"og:locale\" content=\"en_US\" \/>\r\n<meta property=\"og:type\" content=\"article\" \/>\r\n<meta property=\"og:title\" content=\"How would you split with C-Sharp - LDNDeveloper\" \/>\r\n<meta property=\"og:description\" content=\"How would you split with C-Sharp - an interview question.\" \/>\r\n<meta property=\"og:url\" content=\"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/\" \/>\r\n<meta property=\"og:site_name\" content=\"LDNDeveloper\" \/>\r\n<meta property=\"article:published_time\" content=\"2009-04-17T16:07:00+00:00\" \/>\r\n<meta property=\"article:modified_time\" content=\"2013-12-18T20:44:20+00:00\" \/>\r\n<meta property=\"og:image\" content=\"http:\/\/www.unlatched.com\/blog\/uploaded_images\/Untitled-716504.jpg\" \/>\r\n<meta name=\"author\" content=\"andrewpallant\" \/>\r\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\r\n<meta name=\"twitter:creator\" content=\"@ldnDeveloper\" \/>\r\n<meta name=\"twitter:site\" content=\"@LdnDeveloper\" \/>\r\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"andrewpallant\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\r\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/\"},\"author\":{\"name\":\"andrewpallant\",\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/0e7b5e71751000e8f66b17b69ef4ab97\"},\"headline\":\"How would you split with C-Sharp\",\"datePublished\":\"2009-04-17T16:07:00+00:00\",\"dateModified\":\"2013-12-18T20:44:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/\"},\"wordCount\":271,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84\"},\"image\":{\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www.unlatched.com\/blog\/uploaded_images\/Untitled-716504.jpg\",\"keywords\":[\"Humour\"],\"articleSection\":[\"interview\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/\",\"url\":\"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/\",\"name\":\"How would you split with C-Sharp - LDNDeveloper\",\"isPartOf\":{\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www.unlatched.com\/blog\/uploaded_images\/Untitled-716504.jpg\",\"datePublished\":\"2009-04-17T16:07:00+00:00\",\"dateModified\":\"2013-12-18T20:44:20+00:00\",\"description\":\"How would you split with C-Sharp - an interview question.\",\"breadcrumb\":{\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/#primaryimage\",\"url\":\"http:\/\/www.unlatched.com\/blog\/uploaded_images\/Untitled-716504.jpg\",\"contentUrl\":\"http:\/\/www.unlatched.com\/blog\/uploaded_images\/Untitled-716504.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/andrewpallant.ca\/wordpress\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How would you split with C-Sharp\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/#website\",\"url\":\"http:\/\/andrewpallant.ca\/wordpress\/\",\"name\":\"LDNDeveloper\",\"description\":\"Learning, Growing and Sharing.\",\"publisher\":{\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/andrewpallant.ca\/wordpress\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84\",\"name\":\"ldnDeveloper\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/andrewpallant.ca\/wordpress\/wp-content\/uploads\/2017\/05\/cropped-AAEAAQAAAAAAAAXQAAAAJDQxMGRlMzFjLWM4ODctNDk1NC05M2EyLWE1NDNhNTRiZjVlYw-2.jpg\",\"contentUrl\":\"https:\/\/andrewpallant.ca\/wordpress\/wp-content\/uploads\/2017\/05\/cropped-AAEAAQAAAAAAAAXQAAAAJDQxMGRlMzFjLWM4ODctNDk1NC05M2EyLWE1NDNhNTRiZjVlYw-2.jpg\",\"width\":512,\"height\":512,\"caption\":\"ldnDeveloper\"},\"logo\":{\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/image\/\"},\"description\":\"Andrew Pallant (@LdnDeveloper) has been a web, database and desktop developer for over 16 years. Andrew has worked on projects that ranged from factory automation to writing business applications. Most recently he has been heavily involved in various forms for ecommerce projects. Over the years Andrew has worn many hats: Project Manager, IT Manager, Lead Developer, Supervisor of Developers and many more - See more at: http:\/\/www.unlatched.com\/#sthash.8DiTkpKy.dpuf\",\"sameAs\":[\"http:\/\/www.andrewpallant.ca\",\"https:\/\/x.com\/LdnDeveloper\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/0e7b5e71751000e8f66b17b69ef4ab97\",\"name\":\"andrewpallant\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/0.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/0.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"caption\":\"andrewpallant\"},\"url\":\"http:\/\/andrewpallant.ca\/wordpress\/author\/andrewpallant\/\"}]}<\/script>\r\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How would you split with C-Sharp - LDNDeveloper","description":"How would you split with C-Sharp - an interview question.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/","og_locale":"en_US","og_type":"article","og_title":"How would you split with C-Sharp - LDNDeveloper","og_description":"How would you split with C-Sharp - an interview question.","og_url":"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/","og_site_name":"LDNDeveloper","article_published_time":"2009-04-17T16:07:00+00:00","article_modified_time":"2013-12-18T20:44:20+00:00","og_image":[{"url":"http:\/\/www.unlatched.com\/blog\/uploaded_images\/Untitled-716504.jpg"}],"author":"andrewpallant","twitter_card":"summary_large_image","twitter_creator":"@ldnDeveloper","twitter_site":"@LdnDeveloper","twitter_misc":{"Written by":"andrewpallant","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/#article","isPartOf":{"@id":"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/"},"author":{"name":"andrewpallant","@id":"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/0e7b5e71751000e8f66b17b69ef4ab97"},"headline":"How would you split with C-Sharp","datePublished":"2009-04-17T16:07:00+00:00","dateModified":"2013-12-18T20:44:20+00:00","mainEntityOfPage":{"@id":"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/"},"wordCount":271,"commentCount":0,"publisher":{"@id":"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84"},"image":{"@id":"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/#primaryimage"},"thumbnailUrl":"http:\/\/www.unlatched.com\/blog\/uploaded_images\/Untitled-716504.jpg","keywords":["Humour"],"articleSection":["interview"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/","url":"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/","name":"How would you split with C-Sharp - LDNDeveloper","isPartOf":{"@id":"http:\/\/andrewpallant.ca\/wordpress\/#website"},"primaryImageOfPage":{"@id":"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/#primaryimage"},"image":{"@id":"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/#primaryimage"},"thumbnailUrl":"http:\/\/www.unlatched.com\/blog\/uploaded_images\/Untitled-716504.jpg","datePublished":"2009-04-17T16:07:00+00:00","dateModified":"2013-12-18T20:44:20+00:00","description":"How would you split with C-Sharp - an interview question.","breadcrumb":{"@id":"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/#primaryimage","url":"http:\/\/www.unlatched.com\/blog\/uploaded_images\/Untitled-716504.jpg","contentUrl":"http:\/\/www.unlatched.com\/blog\/uploaded_images\/Untitled-716504.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/andrewpallant.ca\/wordpress\/how-would-you-split-with-c\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/andrewpallant.ca\/wordpress\/"},{"@type":"ListItem","position":2,"name":"How would you split with C-Sharp"}]},{"@type":"WebSite","@id":"http:\/\/andrewpallant.ca\/wordpress\/#website","url":"http:\/\/andrewpallant.ca\/wordpress\/","name":"LDNDeveloper","description":"Learning, Growing and Sharing.","publisher":{"@id":"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/andrewpallant.ca\/wordpress\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84","name":"ldnDeveloper","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/image\/","url":"https:\/\/andrewpallant.ca\/wordpress\/wp-content\/uploads\/2017\/05\/cropped-AAEAAQAAAAAAAAXQAAAAJDQxMGRlMzFjLWM4ODctNDk1NC05M2EyLWE1NDNhNTRiZjVlYw-2.jpg","contentUrl":"https:\/\/andrewpallant.ca\/wordpress\/wp-content\/uploads\/2017\/05\/cropped-AAEAAQAAAAAAAAXQAAAAJDQxMGRlMzFjLWM4ODctNDk1NC05M2EyLWE1NDNhNTRiZjVlYw-2.jpg","width":512,"height":512,"caption":"ldnDeveloper"},"logo":{"@id":"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/image\/"},"description":"Andrew Pallant (@LdnDeveloper) has been a web, database and desktop developer for over 16 years. Andrew has worked on projects that ranged from factory automation to writing business applications. Most recently he has been heavily involved in various forms for ecommerce projects. Over the years Andrew has worn many hats: Project Manager, IT Manager, Lead Developer, Supervisor of Developers and many more - See more at: http:\/\/www.unlatched.com\/#sthash.8DiTkpKy.dpuf","sameAs":["http:\/\/www.andrewpallant.ca","https:\/\/x.com\/LdnDeveloper"]},{"@type":"Person","@id":"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/0e7b5e71751000e8f66b17b69ef4ab97","name":"andrewpallant","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/image\/","url":"http:\/\/0.gravatar.com\/avatar\/?s=96&d=mm&r=g","contentUrl":"http:\/\/0.gravatar.com\/avatar\/?s=96&d=mm&r=g","caption":"andrewpallant"},"url":"http:\/\/andrewpallant.ca\/wordpress\/author\/andrewpallant\/"}]}},"_links":{"self":[{"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/posts\/177"}],"collection":[{"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/comments?post=177"}],"version-history":[{"count":3,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/posts\/177\/revisions"}],"predecessor-version":[{"id":1153,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/posts\/177\/revisions\/1153"}],"wp:attachment":[{"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/media?parent=177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/categories?post=177"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/tags?post=177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}