{"id":3574,"date":"2022-05-19T05:31:02","date_gmt":"2022-05-19T05:31:02","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=3574"},"modified":"2022-05-19T05:31:02","modified_gmt":"2022-05-19T05:31:02","slug":"dart-string","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/05\/19\/dart-string\/","title":{"rendered":"Dart String"},"content":{"rendered":"\n<p>Dart String is a sequence of the character or UTF-16 code units. It is used to store the text value. The string can be created using single quotes or double-quotes. The multiline string can be created using the triple-quotes. Strings are immutable; it means you cannot modify it after creation.<\/p>\n\n\n\n<p>In Dart, The&nbsp;<strong>String<\/strong>&nbsp;keyword can be used to declare the string. The syntax of the string declaration is given below.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Syntax:<a href=\"https:\/\/www.javatpoint.com\/dart-string#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-string#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-string#\"><\/a><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>String msg = 'Welcome to JavaTpoint';  \nor  \nString msg1 = \"This is double-quoted string example.\";  \nor  \nString msg2 = ' ' ' line1  \nline2  \nline3''' <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Printing String<\/h2>\n\n\n\n<p>The\u00a0<strong>print()<\/strong>\u00a0function is used to print the string on the screen. The string can be formatted message, any expression, and any other object.\u00a0Dart\u00a0provides\u00a0<strong>${expression},<\/strong>\u00a0which is used to put the value inside a string. Let&#8217; have at look at the following example.<\/p>\n\n\n\n<p><strong>Example &#8211;<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-string#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-string#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-string#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void main() {   \n   String str1 = 'this is an example of a single-line string';   \n   String str2 = \"this is an example of a double-quotes multiline line string\";   \n   String str3 = \"\"\"this is a multiline line   \nstring using the triple-quotes\"\"\";   \n  \n   var  a = 10;  \n   var b = 20;  \n   \n   print(str1);  \n   print(str2);   \n   print(str3);   \n  \n \/\/ We can add expression using the ${expression}.  \n   print(\"The sum is  = ${a+b}\");  \n}  <\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>this is an example of a single-line string\nthis is an example of a double-quotes multiline line string\nthis is a multiline line\n   string using the triple-quotes\nThe sum is  = 30\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">String Concatenation<\/h2>\n\n\n\n<p>The\u00a0<strong>+ or += operator<\/strong>\u00a0is used to merge the two string. The example is given below.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-string#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-string#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-string#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void main() {   \n   String str1 = 'Welcome To ';   \n   String str2 = \"Stringpoint\";   \n   String str3 = str1+str2;  \n  \n   print(str3);   \n}  <\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Welcome To Stringpoint\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">String Interpolation<\/h2>\n\n\n\n<p>The string interpolation is a technique to manipulate the string and create the new string by adding another value. It can be used to evaluate the string including placeholders, variables, and interpolated expression. The\u00a0<strong>${expression}<\/strong>\u00a0is used for string interpolation. The expressions are replaced with their corresponding values. Let&#8217;s understand by the following example.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-string#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-string#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-string#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void main() {   \n   String str1 = 'Hello ';   \n   String str2 = \"World!\";   \n   String str3 = str1+str2;  \n     \n print(str3);   \n  \n   var x = 26;  \n   var y = 10;  \n  \n   print(\"The result is  = ${x%y}\");  \n  \n   var name = \"Peter\";  \n   var roll_nu = 101;  \n     \n   print(\"My name is ${name}, my roll number is ${roll_nu}\");  \n}  <\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Hello World!\nThe result is = 6\nMy name is Peter, my roll number is 101\n<\/code><\/pre>\n\n\n\n<p><strong>Explanation &#8211;<\/strong><\/p>\n\n\n\n<p>In the above code, we have declared two strings variable, created a new string after concatenation, and printed the result.<\/p>\n\n\n\n<p>We have created two variables that hold integer value then performed the mod operation and we printed the result using the string interpolation.<\/p>\n\n\n\n<p>We can use the string interpolation as a placeholder, as we have shown in the above example.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">String Properties<\/h2>\n\n\n\n<p>The Dart provides the following string properties.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><th>Property<\/th><th>Description<\/th><\/tr><tr><td>codeUnits<\/td><td>It returns an unmodified list of the UTF-16 code units of this string.<\/td><\/tr><tr><td>isEmpty<\/td><td>If the string is empty, it returns true.<\/td><\/tr><tr><td>Length<\/td><td>It returns the length of the string including whitespace.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">String Methods<\/h2>\n\n\n\n<p>The Dart provides an extensive range of methods. The list of a few essential methods is given below.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><th>Methods<\/th><th>Descriptions<\/th><\/tr><tr><td>toLowerCase()<\/td><td>It converts all characters of the given string in lowercase.<\/td><\/tr><tr><td>toUpperCase()<\/td><td>It converts all characters of the given string in uppercase.<\/td><\/tr><tr><td>trim()<\/td><td>It eliminates all whitespace from the given string.<\/td><\/tr><tr><td>compareTo()<\/td><td>It compares one string from another.<\/td><\/tr><tr><td>replaceAll()<\/td><td>It replaces all substring that matches the specified pattern with a given string.<\/td><\/tr><tr><td>split()<\/td><td>It splits the string at matches of the specified delimiter and returns the list of the substring.<\/td><\/tr><tr><td>substring()<\/td><td>It returns the substring from start index, inclusive to end index.<\/td><\/tr><tr><td>toString()<\/td><td>It returns the string representation of the given object.<\/td><\/tr><tr><td>codeUnitAt()<\/td><td>It returns the 16-bits code unit at the given index.<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Dart String is a sequence of the character or UTF-16 code units. It is used to store the text value. The string can be created using single quotes or double-quotes. The multiline string can be created using the triple-quotes. Strings are immutable; it means you cannot modify it after creation. In Dart, The&nbsp;String&nbsp;keyword can be [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[917],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/3574"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=3574"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/3574\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=3574"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=3574"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=3574"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}