{"id":3226,"date":"2020-06-17T08:44:00","date_gmt":"2020-06-17T06:44:00","guid":{"rendered":"http:\/\/www.capri-soft.de\/blog\/?p=3226"},"modified":"2020-07-15T08:54:35","modified_gmt":"2020-07-15T06:54:35","slug":"vba-check-if-string-startswith-startwith-or-endswith-endwith","status":"publish","type":"post","link":"https:\/\/www.capri-soft.de\/blog\/?p=3226","title":{"rendered":"VBA: Check if string StartsWith \/ StartWith or EndsWith \/ EndWith"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Problem<\/h2>\n\n\n\n<p>Visual Basic for application does not have function to test, whether a string starts with or ends with another string like it is included in the .NET Framework<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Approach<\/h2>\n\n\n\n<p>Those function can easily created by using the existing string functions<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Solution<\/h2>\n\n\n\n<p>The following code can be pasted to a VBA project:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: vb; title: ; notranslate\" title=\"\">\nPublic Function EndsWith(str As String, ending As String) As Boolean\n     Dim endingLen As Integer\n     endingLen = Len(ending)\n     EndsWith = (Right(Trim(UCase(str)), endingLen) = UCase(ending))\nEnd Function\n\nPublic Function StartsWith(str As String, start As String) As Boolean\n     Dim startLen As Integer\n     startLen = Len(start)\n     StartsWith = (Left(Trim(UCase(str)), startLen) = UCase(start))\nEnd Function\n<\/pre><\/div>\n\n\n<p><span style=\"text-decoration: underline;\">Example usage:<\/span><\/p>\n\n\n\n<p>If StartsWith(&#8222;My string has something in it&#8220;, &#8222;My string&#8220;) Then Msg Box &#8222;It is in it!&#8220;<br>If EndsWith(&#8222;My string has something in it&#8220;, &#8222;in it&#8220;) Then Msg Box &#8222;It is in it!&#8220;<\/p>\n<iframe src=\"http:\/\/www.facebook.com\/plugins\/like.php?href=https%3A%2F%2Fwww.capri-soft.de%2Fblog%2F%3Fp%3D3226&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light\" scrolling=\"no\" frameborder=\"0\" allowTransparency=\"true\" style=\"border:none; overflow:hidden; width:450px;margin-top:5px;\"><\/iframe>","protected":false},"excerpt":{"rendered":"<p>Problem Visual Basic for application does not have function to test, whether a string starts with or ends with another string like it is included in the .NET Framework Approach Those function can easily created by using the existing string functions Solution The following code can be pasted to a VBA project: Example usage: If &hellip; <a href=\"https:\/\/www.capri-soft.de\/blog\/?p=3226\" class=\"more-link\"><span class=\"screen-reader-text\">VBA: Check if string StartsWith \/ StartWith or EndsWith \/ EndWith<\/span> weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[3,12],"tags":[129,128,127,126],"class_list":["post-3226","post","type-post","status-publish","format-standard","hentry","category-programmierung","category-vba","tag-endwith","tag-startswith","tag-string-function","tag-vba"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4yGeN-Q2","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3226"}],"version-history":[{"count":1,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3226\/revisions"}],"predecessor-version":[{"id":3227,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3226\/revisions\/3227"}],"wp:attachment":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}