{"id":7615,"date":"2013-01-28T12:17:26","date_gmt":"2013-01-28T12:17:26","guid":{"rendered":"http:\/\/vskills.in\/certification\/tutorial\/?p=7615"},"modified":"2024-04-12T14:17:06","modified_gmt":"2024-04-12T08:47:06","slug":"string-object-methods-and-regular-expression","status":"publish","type":"page","link":"https:\/\/www.vskills.in\/certification\/tutorial\/string-object-methods-and-regular-expression\/","title":{"rendered":"String object, methods and regular expression"},"content":{"rendered":"<p>Strings are simply groups of characters, like &#8216;Vskills&#8217;, &#8216;Hello world!&#8217;, or even &#8217;23&#8217;. Strings in JavaScript, are always written with single quotes &#8216; or double quotes &#8221; around them and don&#8217;t mix up quotes. String literals (denoted by double or single quotes) and strings returned from String calls in a non-constructor context (i.e., without using the new keyword) are primitive strings. JavaScript automatically converts primitives and String objects, so that it&#8217;s possible to use String object methods for primitive strings. In contexts where a method is to be invoked on a primitive string or a property lookup occurs, JavaScript will automatically wrap the string primitive and call the method or perform the property lookup.<\/p>\n<p>&nbsp;<\/p>\n<p><u>Creating a String object<\/u>: It&#8217;s syntax is<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"211\"><strong>Syntax<\/strong><\/td>\n<td width=\"410\"><strong>Example&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"211\">var val = new String(string);<\/td>\n<td width=\"410\">var a = new String(&#8216;Hello world!&#8217;);<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Adding special characters in a string needs to escape by placing a backslash \\ before it.<\/p>\n<p>String methods \u2013 Various string methods are listed below:<\/p>\n<table width=\"100%\">\n<thead>\n<tr>\n<td width=\"25%\"><strong>Methods<\/strong><\/td>\n<td width=\"75%\"><strong>Description<\/strong><\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td width=\"25%\">charAt(x)<\/td>\n<td width=\"75%\">Returns the character at the &#8220;x&#8221; position within the string.<\/td>\n<\/tr>\n<tr>\n<td width=\"25%\">charCodeAt(x)<\/td>\n<td width=\"75%\">Returns the Unicode value of the character at position &#8220;x&#8221; within the string.<\/td>\n<\/tr>\n<tr>\n<td width=\"25%\">concat(v1, v2,&#8230;)<\/td>\n<td width=\"75%\">Combines one or more strings (arguments v1, v2 etc) into the existing one and returns the combined string. Original string is not modified.<\/td>\n<\/tr>\n<tr>\n<td width=\"25%\">fromCharCode(c1, c2,&#8230;)<\/td>\n<td width=\"75%\">Returns a string created by using the specified sequence of Unicode values (arguments c1, c2 etc). Method of String object, not String instance. For example: String.fromCharCode().<\/td>\n<\/tr>\n<tr>\n<td width=\"25%\">indexOf(substr, [start])<\/td>\n<td width=\"75%\">Searches and (if found) returns the index number of the searched character or substring within the string. If not found, -1 is returned. &#8220;Start&#8221; is an optional argument specifying the position within string to begin the search. Default is 0.<\/td>\n<\/tr>\n<tr>\n<td width=\"25%\">lastIndexOf(substr, [start])<\/td>\n<td width=\"75%\">Searches and (if found) returns the index number of the searched character or substring within the string. Searches the string from end to beginning. If not found, -1 is returned. &#8220;Start&#8221; is an optional argument specifying the position within string to begin the search. Default is string.length-1.<\/td>\n<\/tr>\n<tr>\n<td width=\"25%\">match(regexp)<\/td>\n<td width=\"75%\">Executes a search for a match within a string based on a regular expression. It returns an array of information or null if no match is found.<\/td>\n<\/tr>\n<tr>\n<td width=\"25%\">Replace( regexp, replacetext)<\/td>\n<td width=\"75%\">Searches and replaces the regular expression portion (match) with the replaced text instead.<\/td>\n<\/tr>\n<tr>\n<td width=\"25%\">search(regexp)<\/td>\n<td width=\"75%\">Tests for a match in a string. It returns index of match, or -1 if not found.<\/td>\n<\/tr>\n<tr>\n<td width=\"25%\">slice(start, [end])<\/td>\n<td width=\"75%\">Returns a substring of the string based on the &#8220;start&#8221; and &#8220;end&#8221; index arguments, NOT including the &#8220;end&#8221; index itself. &#8220;End&#8221; is optional, and if none is specified, the slice includes all characters from &#8220;start&#8221; to end of string.<\/td>\n<\/tr>\n<tr>\n<td width=\"25%\">split(delimiter, [limit])<\/td>\n<td width=\"75%\">Splits a string into many according to the specified delimiter, and returns an array containing each element. The optional &#8220;limit&#8221; is an integer that lets you specify the maximum number of elements to return.<\/td>\n<\/tr>\n<tr>\n<td width=\"25%\">substr(start, [length])<\/td>\n<td width=\"75%\">Returns the characters in a string beginning at &#8220;start&#8221; and through the specified number of characters, &#8220;length&#8221;. &#8220;Length&#8221; is optional, and if omitted, up to the end of the string is assumed.<\/td>\n<\/tr>\n<tr>\n<td width=\"25%\">substring(from, [to])<\/td>\n<td width=\"75%\">Returns the characters in a string between &#8220;from&#8221; and &#8220;to&#8221; indexes, NOT including &#8220;to&#8221; inself. &#8220;To&#8221; is optional, and if omitted, up to the end of the string is assumed.<\/td>\n<\/tr>\n<tr>\n<td width=\"25%\">toLowerCase()<\/td>\n<td width=\"75%\">Returns the string with all of its characters converted to lowercase.<\/td>\n<\/tr>\n<tr>\n<td width=\"25%\">toUpperCase()<\/td>\n<td width=\"75%\">Returns the string with all of its characters converted to uppercase.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Regular expressions<\/strong> \u2013 They are very powerful tools for performing pattern matches. This pattern language is mostly used for validation tasks and complex tasks. They are implemented in JavaScript by:<\/p>\n<p>1) Using literal syntax as<\/p>\n<p>var RegularExpression = \/pattern\/<\/p>\n<p>2) When you need to dynamically construct the regular expression, via the RegExp() constructor as &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var RegularExpression = new RegExp(&#8220;pattern&#8221;);<\/p>\n<p>The RegExp() method can dynamically construct the search pattern as a string, and is useful when the pattern is not known ahead of time. Patterns are defined using string literal characters and metacharacters. For example, the following regular expression determines whether a string contains a valid 5-digit value or not<\/p>\n<p>var re5digit=\/^\\d{5}$\/<\/p>\n<p>Characters used for making the regular expression are:<\/p>\n<p><u>Brackets<\/u> &#8211; Brackets are used to find a range of characters:<\/p>\n<table>\n<thead>\n<tr>\n<td width=\"22%\"><strong>Expression<\/strong><\/td>\n<td width=\"78%\"><strong>Description<\/strong><\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>[abc]<\/td>\n<td>Find any character between the brackets<\/td>\n<\/tr>\n<tr>\n<td>[^abc]<\/td>\n<td>Find any character not between the brackets<\/td>\n<\/tr>\n<tr>\n<td>[0-9]<\/td>\n<td>Find any digit from 0 to 9<\/td>\n<\/tr>\n<tr>\n<td>[A-Z]<\/td>\n<td>Find any character from uppercase A to uppercase Z<\/td>\n<\/tr>\n<tr>\n<td>[a-z]<\/td>\n<td>Find any character from lowercase a to lowercase z<\/td>\n<\/tr>\n<tr>\n<td>[A-z]<\/td>\n<td>Find any character from uppercase A to lowercase z<\/td>\n<\/tr>\n<tr>\n<td>[adgk]<\/td>\n<td>Find any character in the given set<\/td>\n<\/tr>\n<tr>\n<td>[^adgk]<\/td>\n<td>Find any character outside the given set<\/td>\n<\/tr>\n<tr>\n<td>(red|blue|green)<\/td>\n<td>Find any of the alternatives specified<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p><u>Metacharacters<\/u> &#8211; Metacharacters are characters with a special meaning:<\/p>\n<table width=\"96%\">\n<thead>\n<tr>\n<td width=\"21%\"><strong>Metacharacter<\/strong><\/td>\n<td width=\"77%\"><strong>Description<\/strong><\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>.<\/td>\n<td>Find a single character, except newline or line terminator<\/td>\n<\/tr>\n<tr>\n<td>\\w<\/td>\n<td>Find a word character<\/td>\n<\/tr>\n<tr>\n<td>\\W<\/td>\n<td>Find a non-word character<\/td>\n<\/tr>\n<tr>\n<td>\\d<\/td>\n<td>Find a digit<\/td>\n<\/tr>\n<tr>\n<td>\\D<\/td>\n<td>Find a non-digit character<\/td>\n<\/tr>\n<tr>\n<td>\\s<\/td>\n<td>Find a whitespace character<\/td>\n<\/tr>\n<tr>\n<td>\\S<\/td>\n<td>Find a non-whitespace character<\/td>\n<\/tr>\n<tr>\n<td>\\b<\/td>\n<td>Find a match at the beginning\/end of a word<\/td>\n<\/tr>\n<tr>\n<td>\\B<\/td>\n<td>Find a match not at the beginning\/end of a word<\/td>\n<\/tr>\n<tr>\n<td>\\0<\/td>\n<td>Find a NUL character<\/td>\n<\/tr>\n<tr>\n<td>\\n<\/td>\n<td>Find a new line character<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n\n\n<p><a href=\"https:\/\/www.vskills.in\/certification\/tutorial\/dhtml-and-javascript-developer\/\" target=\"_blank\" rel=\"noreferrer noopener\">Back to Tutorial<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Strings are simply groups of characters, like &#8216;Vskills&#8217;, &#8216;Hello world!&#8217;, or even &#8217;23&#8217;. Strings in JavaScript, are always written with single quotes &#8216; or double quotes &#8221; around them and don&#8217;t mix up quotes. String literals (denoted by double or single quotes) and strings returned from String calls in a non-constructor context (i.e., without using&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[3352],"tags":[2816,2815],"class_list":["post-7615","page","type-page","status-publish","hentry","category-dhtml-and-javascript","tag-methods-and-regular-expression","tag-string-object"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>String object, methods and regular expression - Tutorial<\/title>\n<meta name=\"description\" content=\"String object, methods and regular expression. Govt of India Certification for DHTML and Javascript professionals. Get Certified and improve employability. Certification assesses candidates in DHTML.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.vskills.in\/certification\/tutorial\/string-object-methods-and-regular-expression\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"String object, methods and regular expression - Tutorial\" \/>\n<meta property=\"og:description\" content=\"String object, methods and regular expression. Govt of India Certification for DHTML and Javascript professionals. Get Certified and improve employability. Certification assesses candidates in DHTML.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.vskills.in\/certification\/tutorial\/string-object-methods-and-regular-expression\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/vskills.in\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-12T08:47:06+00:00\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/string-object-methods-and-regular-expression\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/string-object-methods-and-regular-expression\/\",\"name\":\"String object, methods and regular expression - Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\"},\"datePublished\":\"2013-01-28T12:17:26+00:00\",\"dateModified\":\"2024-04-12T08:47:06+00:00\",\"description\":\"String object, methods and regular expression. Govt of India Certification for DHTML and Javascript professionals. Get Certified and improve employability. Certification assesses candidates in DHTML.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/string-object-methods-and-regular-expression\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.vskills.in\/certification\/tutorial\/string-object-methods-and-regular-expression\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/string-object-methods-and-regular-expression\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"String object, methods and regular expression\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"name\":\"Tutorial\",\"description\":\"Vskills - A initiative in elearning and certification\",\"publisher\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\",\"name\":\"Vskills\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"contentUrl\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"width\":73,\"height\":55,\"caption\":\"Vskills\"},\"image\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/vskills.in\/\",\"https:\/\/x.com\/vskills_in\",\"https:\/\/www.linkedin.com\/company-beta\/1371554\/\",\"https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"String object, methods and regular expression - Tutorial","description":"String object, methods and regular expression. Govt of India Certification for DHTML and Javascript professionals. Get Certified and improve employability. Certification assesses candidates in DHTML.","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:\/\/www.vskills.in\/certification\/tutorial\/string-object-methods-and-regular-expression\/","og_locale":"en_US","og_type":"article","og_title":"String object, methods and regular expression - Tutorial","og_description":"String object, methods and regular expression. Govt of India Certification for DHTML and Javascript professionals. Get Certified and improve employability. Certification assesses candidates in DHTML.","og_url":"https:\/\/www.vskills.in\/certification\/tutorial\/string-object-methods-and-regular-expression\/","og_site_name":"Tutorial","article_publisher":"https:\/\/www.facebook.com\/vskills.in\/","article_modified_time":"2024-04-12T08:47:06+00:00","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/string-object-methods-and-regular-expression\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/string-object-methods-and-regular-expression\/","name":"String object, methods and regular expression - Tutorial","isPartOf":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website"},"datePublished":"2013-01-28T12:17:26+00:00","dateModified":"2024-04-12T08:47:06+00:00","description":"String object, methods and regular expression. Govt of India Certification for DHTML and Javascript professionals. Get Certified and improve employability. Certification assesses candidates in DHTML.","breadcrumb":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/string-object-methods-and-regular-expression\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.vskills.in\/certification\/tutorial\/string-object-methods-and-regular-expression\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/string-object-methods-and-regular-expression\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vskills.in\/certification\/tutorial\/"},{"@type":"ListItem","position":2,"name":"String object, methods and regular expression"}]},{"@type":"WebSite","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","name":"Tutorial","description":"Vskills - A initiative in elearning and certification","publisher":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization","name":"Vskills","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","contentUrl":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","width":73,"height":55,"caption":"Vskills"},"image":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/vskills.in\/","https:\/\/x.com\/vskills_in","https:\/\/www.linkedin.com\/company-beta\/1371554\/","https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw"]}]}},"_links":{"self":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/7615","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/comments?post=7615"}],"version-history":[{"count":7,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/7615\/revisions"}],"predecessor-version":[{"id":82878,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/7615\/revisions\/82878"}],"wp:attachment":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/media?parent=7615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/categories?post=7615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/tags?post=7615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}