{"id":2326,"date":"2013-02-12T14:00:16","date_gmt":"2013-02-12T06:00:16","guid":{"rendered":"http:\/\/www.vbtutor.net\/index.php\/"},"modified":"2018-06-24T17:50:09","modified_gmt":"2018-06-24T09:50:09","slug":"visual-basic-2012-lesson-8-string-manipulation","status":"publish","type":"page","link":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-8-string-manipulation\/","title":{"rendered":"Visual Basic 2012 Lesson 8- String Manipulation"},"content":{"rendered":"<h4 style=\"text-align: center;\"><strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-7-mathematical-operations\/\">[Lesson 7]<\/a> &lt;&lt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-tutorial\/\">[CONTENTS]<\/a> &gt;&gt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-9-using-if-then-else\/\">[Lesson 9]<\/a><\/strong><\/h4>\n<h3>8.1 String Manipulation Using + and &amp; signs.<\/h3>\n<p>In Visual Basic 2012, strings can be manipulated using the &amp; sign and the + sign, both perform the string concatenation which means combining two or more smaller strings into larger strings. For example, we can join &#8220;Visual&#8221;,&#8221;Basic&#8221; and &#8220;2012&#8221; into &#8220;Visual Basic 2012&#8221; using &#8220;Visual&#8221;&amp;&#8221;Basic&#8221; or &#8220;Visual &#8220;+&#8221;Basic&#8221;, as shown in the Examples below<\/p>\n<h4>Example 8.1(a)<\/h4>\n<pre style=\"font-size: 110%;\">Public Class Form1\r\n\r\nPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click\r\nDim text1, text2, text3, text4 As String\r\n text1 = \"Visual\"\r\n text2 = \"Basic\"\r\n text3=\"2012\"\r\n text4 = text1 + text2+text3\r\n MsgBox(text4)\r\n\r\nEnd Sub\r\nEnd Class\r\n<\/pre>\n<p>The line text4=text1+ text2 + text3 can be replaced by text4=text1 &amp; text2 &amp;text3 and produces the same output. However, if one of the variables is declared as numeric data type, you cannot use the + sign, you can only use the &amp; sign.<\/p>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"1777484012\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4>Example 8.1(b)<\/h4>\n<pre style=\"font-size: 110%;\">Dim text1, text3 as string\r\nDim Text2 As Integer\r\n\r\n text1 = \"Visual\"\r\n text2=22\r\n text3=text1+text2\r\n Label1.Text = text3\r\n<\/pre>\n<p>This code will produce an error because of data mismatch.However, using &amp; instead of + will be all right.<\/p>\n<pre style=\"font-size: 110%;\">Dim text1, text3 as string\r\nDim Text2 As Integer\r\n text1 = \"Visual\"\r\n text2=22\r\n text3=text1 &amp; text2\r\n Label1.Text = text3\r\n<\/pre>\n<p>You can combine more than two strings to form a larger string, like the following example:<\/p>\n<pre style=\"font-size: 110%;\">Public Class Form1\r\n\r\nPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click\r\nDim text1, text2, text3, text4, text5, text6 As String\r\n text1 = \"Welcome\"\r\n text2 = \" to\"\r\n text3 = \" Visual\"\r\n text4 = \" Basic\"\r\n text5 = \" 2012\"\r\n text6 = text1 + text2 + text3+text4+text5\r\n Label1.Text = text6\r\nEnd Sub\r\n\r\nEnd Class\r\n<\/pre>\n<p>Running the above program will produce the following screen shot.<br \/>\n<a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2013\/02\/vb2012-Fig-8.1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2336\" title=\"vb2012 Fig 8.1\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2013\/02\/vb2012-Fig-8.1.jpg\" alt=\"Visual Basic 2012\" width=\"341\" height=\"300\" \/><\/a><br \/>\n<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"1777484012\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h3>8.2 String Manipulation Using VB2012 Built-in Functions<\/h3>\n<p>A function is similar to a normal procedure but the main purpose of the function is to accept a certain input and return a value which is passed on to the main program to finish the execution.There are numerous string manipulation functions built into Visual Basic 2012 but I will only discuss a few here and will explain the rest of them in later lessons.<\/p>\n<h4>8.2 (a) The Len Function<\/h4>\n<p>The Len function returns an integer value which is the length of a phrase or a sentence, including the empty spaces. The syntax is<br \/>\n<strong> Len (&#8220;Phrase&#8221;)<\/strong><\/p>\n<p>For example,<\/p>\n<pre style=\"font-size: 110%;\">Len (Visual Basic) = 12\r\n<\/pre>\n<pre style=\"font-size: 110%;\">and\r\nLen (\"welcome to VB tutorial\") = 22\r\n<\/pre>\n<p><strong>Example 8.3<\/strong><\/p>\n<p>Public Class Form1<\/p>\n<pre style=\"font-size: 110%;\">Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click\r\n Label1.Text = Len(TextBox1.Text)\r\nEnd Sub\r\nEnd Class\r\n<\/pre>\n<p>The output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_8.2.gif\" alt=\"\" width=\"300\" height=\"300\" \/><\/p>\n<h4>8.2(b) The Right Function<\/h4>\n<p>The Right function extracts the right portion of a phrase. The format for Visual Basic 6 is<\/p>\n<pre style=\"font-size: 110%;\">Right (\"Phrase\", n)\r\n<\/pre>\n<p>Where n is the starting position from the right of the phase where the portion of the phrase is going to be extracted. For example,<\/p>\n<pre style=\"font-size: 110%;\">Right(\"Visual Basic\", 4) = asic\r\n<\/pre>\n<p>However, this syntax is not applicable in VB2012. In VB2012, we need use the following format<\/p>\n<pre style=\"font-size: 110%;\">Microsoft.VisualBasic.Right(\"Phrase\",n)\r\n<\/pre>\n<h4>Example 8.2(a)<\/h4>\n<pre style=\"font-size: 110%;\">Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click\r\nDim text1 As String\r\n text1 = TextBox1.Text\r\n Label1.Text = Microsoft.VisualBasic.Right(text1, 4)\r\nEnd Sub\r\n<\/pre>\n<p>The above program returns four rightmost characters of the phrase entered into the textbox.<\/p>\n<p>The Output:<\/p>\n<p><center><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_8.3.gif\" alt=\"Visual Basic 2012\" width=\"300\" height=\"300\" \/>\u00a0<\/center><br \/>\n*The reason of using the full reference is because many objects have the Right properties so using Right on its own will make it ambiguous to Visual Basic 2012.<\/p>\n<h4>8.2(c)The Left Function<\/h4>\n<p>The Left function extracts the left portion of a phrase. The syntax \u00a0is<\/p>\n<pre style=\"font-size: 110%;\">Microsoft.VisualBasic.Left(\"Phrase\",n)<\/pre>\n<p>Where n is the starting position from the left of the phase where the portion of the phrase is going to be extracted. For example,<\/p>\n<p>Microsoft.VisualBasic.Left (&#8220;Visual Basic&#8221;, 4) = Visu .<br \/>\n<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block;\" data-ad-format=\"autorelaxed\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"6598395509\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4 style=\"text-align: center;\"><strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-7-mathematical-operations\/\">[Lesson 7]<\/a> &lt;&lt;\u00a0<a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-tutorial\/\">[CONTENTS]<\/a> &gt;&gt;\u00a0<a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-9-using-if-then-else\/\">[Lesson 9]<\/a><\/strong><\/h4>\n","protected":false},"excerpt":{"rendered":"<p>[Lesson 7] &lt;&lt; [CONTENTS] &gt;&gt; [Lesson 9] 8.1 String Manipulation Using + and &amp; signs. In Visual Basic 2012, strings can be manipulated using the &amp; sign and the + sign, both perform the string concatenation which means combining two or more smaller strings into larger strings. For example, we can join &#8220;Visual&#8221;,&#8221;Basic&#8221; and &#8220;2012&#8221; &hellip; <a href=\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-8-string-manipulation\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Visual Basic 2012 Lesson 8- String Manipulation<\/span><\/a><\/p>\n","protected":false},"author":23013,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-2326","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Visual Basic 2012 Lesson 8- String Manipulation - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB<\/title>\n<meta name=\"description\" content=\"This visual basic 2012 shows you how to manipulate strings in visual basic 2012\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson8.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Visual Basic 2012 Lesson 8- String Manipulation - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"og:description\" content=\"This visual basic 2012 shows you how to manipulate strings in visual basic 2012\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson8.html\" \/>\n<meta property=\"og:site_name\" content=\"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Vbtutor\" \/>\n<meta property=\"article:modified_time\" content=\"2018-06-24T09:50:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2013\/02\/vb2012-Fig-8.1.jpg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@liewvk\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-8-string-manipulation\/\",\"url\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson8.html\",\"name\":\"Visual Basic 2012 Lesson 8- String Manipulation - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\",\"isPartOf\":{\"@id\":\"https:\/\/www.vbtutor.net\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson8.html#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson8.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2013\/02\/vb2012-Fig-8.1.jpg\",\"datePublished\":\"2013-02-12T06:00:16+00:00\",\"dateModified\":\"2018-06-24T09:50:09+00:00\",\"description\":\"This visual basic 2012 shows you how to manipulate strings in visual basic 2012\",\"breadcrumb\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson8.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson8.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson8.html#primaryimage\",\"url\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2013\/02\/vb2012-Fig-8.1.jpg\",\"contentUrl\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2013\/02\/vb2012-Fig-8.1.jpg\",\"width\":\"341\",\"height\":\"300\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson8.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vbtutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visual Basic 2012 Lesson 8- String Manipulation\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vbtutor.net\/#website\",\"url\":\"https:\/\/www.vbtutor.net\/\",\"name\":\"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\",\"description\":\"Start learning Visual Basic from beginner to advanced. Includes VB.NET, VBA, and classic VB tutorials for students and professionals.\",\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Visual Basic 2012 Lesson 8- String Manipulation - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"This visual basic 2012 shows you how to manipulate strings in visual basic 2012","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":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson8.html","og_locale":"en_US","og_type":"article","og_title":"Visual Basic 2012 Lesson 8- String Manipulation - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","og_description":"This visual basic 2012 shows you how to manipulate strings in visual basic 2012","og_url":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson8.html","og_site_name":"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","article_publisher":"https:\/\/www.facebook.com\/Vbtutor","article_modified_time":"2018-06-24T09:50:09+00:00","og_image":[{"url":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2013\/02\/vb2012-Fig-8.1.jpg","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_site":"@liewvk","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-8-string-manipulation\/","url":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson8.html","name":"Visual Basic 2012 Lesson 8- String Manipulation - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","isPartOf":{"@id":"https:\/\/www.vbtutor.net\/#website"},"primaryImageOfPage":{"@id":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson8.html#primaryimage"},"image":{"@id":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson8.html#primaryimage"},"thumbnailUrl":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2013\/02\/vb2012-Fig-8.1.jpg","datePublished":"2013-02-12T06:00:16+00:00","dateModified":"2018-06-24T09:50:09+00:00","description":"This visual basic 2012 shows you how to manipulate strings in visual basic 2012","breadcrumb":{"@id":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson8.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson8.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson8.html#primaryimage","url":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2013\/02\/vb2012-Fig-8.1.jpg","contentUrl":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2013\/02\/vb2012-Fig-8.1.jpg","width":"341","height":"300"},{"@type":"BreadcrumbList","@id":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson8.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vbtutor.net\/"},{"@type":"ListItem","position":2,"name":"Visual Basic 2012 Lesson 8- String Manipulation"}]},{"@type":"WebSite","@id":"https:\/\/www.vbtutor.net\/#website","url":"https:\/\/www.vbtutor.net\/","name":"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"Start learning Visual Basic from beginner to advanced. Includes VB.NET, VBA, and classic VB tutorials for students and professionals.","inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/2326","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/users\/23013"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/comments?post=2326"}],"version-history":[{"count":42,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/2326\/revisions"}],"predecessor-version":[{"id":13099,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/2326\/revisions\/13099"}],"wp:attachment":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=2326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=2326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=2326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}