{"id":1082,"date":"2012-04-06T16:31:05","date_gmt":"2012-04-06T08:31:05","guid":{"rendered":"http:\/\/www.vbtutor.net\/index.php\/"},"modified":"2018-06-24T19:02:51","modified_gmt":"2018-06-24T11:02:51","slug":"visual-basic-2010-lesson-8","status":"publish","type":"page","link":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-8\/","title":{"rendered":"Visual Basic 2010 Lesson 8- String Manipulation"},"content":{"rendered":"<h4 style=\"text-align: center;\"><strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-7\/\">[Lesson 7]<\/a> &lt;&lt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-tutorial\/\">[CONTENTS]<\/a> &gt;&gt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-9\/\">[Lesson 9]<\/a><\/strong><\/h4>\n<p>Generally, we have to deal with two types of data, the numeric and the non-numeric data types. The non-numeric data again divided into a few types, the most common one being text, or string. Examples of the string are words, sentences, names, addresses, gender, cities, book titles and much more. In this lesson, we shall learn how to process and manipulate strings in visual basic 2010<\/p>\n<h3>8.1 String Manipulation Using + and &amp; signs.<\/h3>\n<p>In Visual Basic 2010, Strings can be manipulated using the &amp; sign and the + sign, both perform the string concatenation which by combining two or more smaller strings into larger strings. For example, we can join &#8220;Visual&#8221; and &#8220;Basic&#8221; into &#8220;Visual Basic&#8221; using &#8220;Visual&#8221;&amp;&#8221;Basic&#8221; or &#8220;Visual &#8220;+&#8221;Basic&#8221;, as shown in the example below<\/p>\n<h4>Example 8.1(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, text2, text3 As String\r\n text1 = \"Visual\"\r\n text2 = \"Basic\"\r\n text3 = text1 + text2\r\n Label1.Text = text3\r\nEnd Sub\r\n<\/pre>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\"\n     style=\"display:block; text-align:center;\"\n     data-ad-layout=\"in-article\"\n     data-ad-format=\"fluid\"\n     data-ad-client=\"ca-pub-3033628290023372\"\n     data-ad-slot=\"1723562988\"><\/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%; width: 70%;\">\r\nDim text1, text3 as string\r\nDim Text2 As Integertext1 = \"Visual\"\r\n text2=22\r\n text3=text1+text2\r\n Label1.Text = text3\r\n<\/pre>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\"\n     style=\"display:block; text-align:center;\"\n     data-ad-layout=\"in-article\"\n     data-ad-format=\"fluid\"\n     data-ad-client=\"ca-pub-3033628290023372\"\n     data-ad-slot=\"1723562988\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\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%; width: 70%;\">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\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 = \" 2010\"\r\n text6 = text1 + text2 + text3+text4+text5\r\n Label1.Text = text6\r\nEnd Sub\r\nEnd Class\r\n<\/pre>\n<p>Running the above program will produce the following screen shot.<\/p>\n<p><center><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_8.1.gif\" alt=\"\" width=\"300\" height=\"300\" \/><\/center><\/p>\n<h3>8.2 String Manipulation Using Visual Basic 2010 Built-in Functions<\/h3>\n<p>A function is similar to a normal procedure. However, the main purpose of a function is to accept an input and return a value. The value then is passed on to the main program to finish the in this lesson here and will explain the rest of them in later lessons.<\/p>\n<h4>8.2 (a) The Len Function<\/h4>\n<p>The length function returns an integer value equals to the length of a phrase or a sentence, including the empty spaces. The syntax is<\/p>\n<pre style=\"font-size: 110%; width: 50%;\">Len (\"Phrase\")\r\n<\/pre>\n<p>For example,<\/p>\n<pre style=\"font-size: 110%; width: 70%;\">Len (Visual Basic) = 12<\/pre>\n<p>and<\/p>\n<pre style=\"font-size: 110%; width: 70%;\"> Len (welcome to VB tutorial) = 22<\/pre>\n<h4>Example 8.3<\/h4>\n<pre style=\"font-size: 110%;\">Public Class Form1\r\nPrivate 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<p>8.2(b) The Right Function<\/p>\n<p>The Right function extracts the right portion of a phrase. The syntax for Visual Basic 6 is<\/p>\n<pre style=\"font-size: 110%; width: 50%;\">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%; width: 70%;\">Right(\"Visual Basic\", 4) = asic\r\n<\/pre>\n<p>However, this syntax is not applicable in VB2010. In VB2010, we need use the following syntax<\/p>\n<pre style=\"font-size: 110%; width: 70%;\">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 will return four rightmost characters of the phrase entered into the textbox.<\/p>\n<p>The Output:<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_8.3.gif\" alt=\"\" width=\"300\" height=\"300\" \/><\/p>\n<p>*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 VB2010.<\/p>\n<h4>8.2(c)The Left Function<\/h4>\n<p>The Left function extracts the left portion of a phrase. The syntax is<\/p>\n<pre style=\"font-size: 110%; width: 70%;\">Microsoft.VisualBasic.Left(\"Phrase\",n)\r\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<pre style=\"font-size: 110%; width: 70%;\">Microsoft.VisualBasic.Left (\"Visual Basic\", 4) = Visu .\r\n<\/pre>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\"\n     style=\"display:block\"\n     data-ad-format=\"autorelaxed\"\n     data-ad-client=\"ca-pub-3033628290023372\"\n     data-ad-slot=\"8075128701\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<p style=\"text-align: center;\"><strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-7\/\">[Lesson 7]<\/a> &lt;&lt;\u00a0<a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-tutorial\/\">[CONTENTS]<\/a> &gt;&gt;\u00a0<a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-9\/\">[Lesson 9]<\/a><\/strong><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>[Lesson 7] &lt;&lt; [CONTENTS] &gt;&gt; [Lesson 9] Generally, we have to deal with two types of data, the numeric and the non-numeric data types. The non-numeric data again divided into a few types, the most common one being text, or string. Examples of the string are words, sentences, names, addresses, gender, cities, book titles and &hellip; <a href=\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-8\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Visual Basic 2010 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-1082","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 2010 Lesson 8- String Manipulation - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB<\/title>\n<meta name=\"description\" content=\"This visual basic 2010 lesson illustrates string manipulation in visual basic 2010\" \/>\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\/vb2010\/vb2010_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 2010 Lesson 8- String Manipulation - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"og:description\" content=\"This visual basic 2010 lesson illustrates string manipulation in visual basic 2010\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_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-24T11:02:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_8.1.gif\" \/>\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-2010-lesson-8\/\",\"url\":\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson8.html\",\"name\":\"Visual Basic 2010 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\/vb2010\/vb2010_Lesson8.html#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson8.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_8.1.gif\",\"datePublished\":\"2012-04-06T08:31:05+00:00\",\"dateModified\":\"2018-06-24T11:02:51+00:00\",\"description\":\"This visual basic 2010 lesson illustrates string manipulation in visual basic 2010\",\"breadcrumb\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson8.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson8.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson8.html#primaryimage\",\"url\":\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_8.1.gif\",\"contentUrl\":\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_8.1.gif\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson8.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vbtutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visual Basic 2010 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 2010 Lesson 8- String Manipulation - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"This visual basic 2010 lesson illustrates string manipulation in visual basic 2010","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\/vb2010\/vb2010_Lesson8.html","og_locale":"en_US","og_type":"article","og_title":"Visual Basic 2010 Lesson 8- String Manipulation - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","og_description":"This visual basic 2010 lesson illustrates string manipulation in visual basic 2010","og_url":"http:\/\/www.vbtutor.net\/vb2010\/vb2010_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-24T11:02:51+00:00","og_image":[{"url":"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_8.1.gif","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-2010-lesson-8\/","url":"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson8.html","name":"Visual Basic 2010 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\/vb2010\/vb2010_Lesson8.html#primaryimage"},"image":{"@id":"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson8.html#primaryimage"},"thumbnailUrl":"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_8.1.gif","datePublished":"2012-04-06T08:31:05+00:00","dateModified":"2018-06-24T11:02:51+00:00","description":"This visual basic 2010 lesson illustrates string manipulation in visual basic 2010","breadcrumb":{"@id":"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson8.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson8.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson8.html#primaryimage","url":"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_8.1.gif","contentUrl":"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_8.1.gif"},{"@type":"BreadcrumbList","@id":"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson8.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vbtutor.net\/"},{"@type":"ListItem","position":2,"name":"Visual Basic 2010 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\/1082","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=1082"}],"version-history":[{"count":54,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/1082\/revisions"}],"predecessor-version":[{"id":13130,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/1082\/revisions\/13130"}],"wp:attachment":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=1082"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=1082"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=1082"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}