CINXE.COM
String class - dart:core library - Dart API
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, user-scalable=no"> <meta name="description" content="API docs for the String class from the dart:core library, for the Dart programming language."> <title>String class - dart:core library - Dart API</title> <link rel="canonical" href="https://api.dart.dev/dart-core/String-class.html"> <link rel="preconnect" href="https://fonts.gstatic.com"> <link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,300;0,400;0,500;0,700;1,400&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0" rel="stylesheet"> <link rel="stylesheet" href="../static-assets/github.css?v1"> <link rel="stylesheet" href="../static-assets/styles.css?v1"> <link rel="icon" href="../static-assets/favicon.png?v1"> <!-- Google tag (gtag.js) --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-VVQ8908SJ5"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-VVQ8908SJ5'); </script> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link rel="preload" href="https://fonts.googleapis.com/css2?family=Google+Sans+Text:wght@400&family=Google+Sans:wght@500&display=swap" as="style"> <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Google+Sans+Text:wght@400&family=Google+Sans:wght@500&display=swap"> <link rel="stylesheet" href="https://www.gstatic.com/glue/cookienotificationbar/cookienotificationbar.min.css"> </head> <body data-base-href="../" data-using-base-href="false" class="light-theme"> <div id="overlay-under-drawer"></div> <header id="title"> <span id="sidenav-left-toggle" class="material-symbols-outlined" role="button" tabindex="0">menu</span> <ol class="breadcrumbs gt-separated dark hidden-xs"> <li><a href="../index.html">Dart</a></li> <li><a href="../dart-core/dart-core-library.html">dart:core</a></li> <li class="self-crumb">String class</li> </ol> <div class="self-name">String</div> <form class="search navbar-right" role="search"> <input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search..."> </form> <div class="toggle" id="theme-button" title="Toggle brightness"> <label for="theme"> <input type="checkbox" id="theme" value="light-theme"> <span id="dark-theme-button" class="material-symbols-outlined"> dark_mode </span> <span id="light-theme-button" class="material-symbols-outlined"> light_mode </span> </label> </div> </header> <main> <div id="dartdoc-main-content" class="main-content" data-above-sidebar="dart-core/dart-core-library-sidebar.html" data-below-sidebar="dart-core/String-class-sidebar.html"> <div> <div id="external-links" class="btn-group"><a title="View source code" class="source-link" href="https://github.com/dart-lang/sdk/blob/88c9758ef131d430d8ce595c6bfb4c90574d3ddd/sdk/lib/core/string.dart#L108"><span class="material-symbols-outlined">description</span></a></div> <h1><span class="kind-class">String</span> class <a href="https://dart.dev/language/class-modifiers#abstract" class="feature feature-abstract" title="This type can not be directly constructed.">abstract</a> <a href="https://dart.dev/language/class-modifiers#final" class="feature feature-final" title="This class can neither be extended, implemented, nor mixed in.">final</a> </h1></div> <section class="desc markdown"> <p>A sequence of UTF-16 code units.</p> <p>Strings are mainly used to represent text. A character may be represented by multiple code points, each code point consisting of one or two code units. For example, the Papua New Guinea flag character requires four code units to represent two code points, but should be treated like a single character: "馃嚨馃嚞". Platforms that do not support the flag character may show the letters "PG" instead. If the code points are swapped, it instead becomes the Guadeloupe flag "馃嚞馃嚨" ("GP").</p> <p>A string can be either single or multiline. Single line strings are written using matching single or double quotes, and multiline strings are written using triple quotes. The following are all valid Dart strings:</p> <pre class="language-dart"><code class="language-dart">'Single quotes'; "Double quotes"; 'Double quotes in "single" quotes'; "Single quotes in 'double' quotes"; '''A multiline string'''; """ Another multiline string"""; </code></pre> <p>Strings are immutable. Although you cannot change a string, you can perform an operation on a string which creates a new string:</p> <pre class="language-dart"><code class="language-dart">const string = 'Dart is fun'; print(string.substring(0, 4)); // 'Dart' </code></pre> <p>You can use the plus (<code>+</code>) operator to concatenate strings:</p> <pre class="language-dart"><code class="language-dart">const string = 'Dart ' + 'is ' + 'fun!'; print(string); // 'Dart is fun!' </code></pre> <p>Adjacent string literals are concatenated automatically:</p> <pre class="language-dart"><code class="language-dart">const string = 'Dart ' 'is ' 'fun!'; print(string); // 'Dart is fun!' </code></pre> <p>You can use <code>${}</code> to interpolate the value of Dart expressions within strings. The curly braces can be omitted when evaluating identifiers:</p> <pre class="language-dart"><code class="language-dart">const string = 'dartlang'; print('$string has ${string.length} letters'); // dartlang has 8 letters </code></pre> <p>A string is represented by a sequence of Unicode UTF-16 code units accessible through the <a href="../dart-core/String/codeUnitAt.html">codeUnitAt</a> or the <a href="../dart-core/String/codeUnits.html">codeUnits</a> members:</p> <pre class="language-dart"><code class="language-dart">const string = 'Dart'; final firstCodeUnit = string.codeUnitAt(0); print(firstCodeUnit); // 68, aka U+0044, the code point for 'D'. final allCodeUnits = string.codeUnits; print(allCodeUnits); // [68, 97, 114, 116] </code></pre> <p>A string representation of the individual code units is accessible through the index operator:</p> <pre class="language-dart"><code class="language-dart">const string = 'Dart'; final charAtIndex = string[0]; print(charAtIndex); // 'D' </code></pre> <p>The characters of a string are encoded in UTF-16. Decoding UTF-16, which combines surrogate pairs, yields Unicode code points. Following a similar terminology to Go, Dart uses the name 'rune' for an integer representing a Unicode code point. Use the <a href="../dart-core/String/runes.html">runes</a> property to get the runes of a string:</p> <pre class="language-dart"><code class="language-dart">const string = 'Dart'; final runes = string.runes.toList(); print(runes); // [68, 97, 114, 116] </code></pre> <p>For a character outside the Basic Multilingual Plane (plane 0) that is composed of a surrogate pair, <a href="../dart-core/String/runes.html">runes</a> combines the pair and returns a single integer. For example, the Unicode character for a musical G-clef ('饾劄') with rune value 0x1D11E consists of a UTF-16 surrogate pair: <code>0xD834</code> and <code>0xDD1E</code>. Using <a href="../dart-core/String/codeUnits.html">codeUnits</a> returns the surrogate pair, and using <code>runes</code> returns their combined value:</p> <pre class="language-dart"><code class="language-dart">const clef = '\u{1D11E}'; for (final item in clef.codeUnits) { print(item.toRadixString(16)); // d834 // dd1e } for (final item in clef.runes) { print(item.toRadixString(16)); // 1d11e } </code></pre> <p>The <code>String</code> class cannot be extended or implemented. Attempting to do so yields a compile-time error.</p> <h2 id="other-resources">Other resources</h2> <ul> <li><a href="../dart-core/StringBuffer-class.html">StringBuffer</a> to efficiently build a string incrementally.</li> <li><a href="../dart-core/RegExp-class.html">RegExp</a> to work with regular expressions.</li> <li><a href="https://dart.dev/guides/libraries/library-tour#strings-and-regular-expressions">Strings and regular expressions</a></li> </ul> </section> <section> <dl class="dl-horizontal"> <dt>Implemented types</dt> <dd> <ul class="comma-separated clazz-relationships"> <li><a href="../dart-core/Comparable-class.html">Comparable</a><span class="signature"><<wbr><span class="type-parameter"><a href="../dart-core/String-class.html">String</a></span>></span></li> <li><a href="../dart-core/Pattern-class.html">Pattern</a></li> </ul> </dd> <dt>Available Extensions</dt> <dd><ul class="comma-separated clazz-relationships"> <li><a href="../dart-js_interop/StringToJSString.html">StringToJSString</a></li> </ul></dd> </dl> </section> <section class="summary offset-anchor" id="constructors"> <h2>Constructors</h2> <dl class="constructor-summary-list"> <dt id="String.fromCharCode" class="callable"> <span class="name"><a href="../dart-core/String/String.fromCharCode.html">String.fromCharCode</a></span><span class="signature">(<span class="parameter" id="fromCharCode-param-charCode"><span class="type-annotation"><a href="../dart-core/int-class.html">int</a></span> <span class="parameter-name">charCode</span></span>)</span> </dt> <dd> Allocates a new string containing the specified <code>charCode</code>. <div class="constructor-modifier features">factory</div> </dd> <dt id="String.fromCharCodes" class="callable"> <span class="name"><a href="../dart-core/String/String.fromCharCodes.html">String.fromCharCodes</a></span><span class="signature">(<span class="parameter" id="fromCharCodes-param-charCodes"><span class="type-annotation"><a href="../dart-core/Iterable-class.html">Iterable</a><span class="signature"><<wbr><span class="type-parameter"><a href="../dart-core/int-class.html">int</a></span>></span></span> <span class="parameter-name">charCodes</span>, [</span><span class="parameter" id="fromCharCodes-param-start"><span class="type-annotation"><a href="../dart-core/int-class.html">int</a></span> <span class="parameter-name">start</span> = <span class="default-value">0</span>, </span><span class="parameter" id="fromCharCodes-param-end"><span class="type-annotation"><a href="../dart-core/int-class.html">int</a>?</span> <span class="parameter-name">end</span></span>])</span> </dt> <dd> Allocates a new string containing the specified <code>charCodes</code>. <div class="constructor-modifier features">factory</div> </dd> <dt id="String.fromEnvironment" class="callable"> <span class="name"><a href="../dart-core/String/String.fromEnvironment.html">String.fromEnvironment</a></span><span class="signature">(<span class="parameter" id="fromEnvironment-param-name"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a></span> <span class="parameter-name">name</span>, {</span><span class="parameter" id="fromEnvironment-param-defaultValue"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a></span> <span class="parameter-name">defaultValue</span> = <span class="default-value">""</span></span>})</span> </dt> <dd> Value for <code>name</code> in the compilation configuration environment declaration. <div class="constructor-modifier features">const</div> <div class="constructor-modifier features">factory</div> </dd> </dl> </section> <section class="summary offset-anchor" id="instance-properties"> <h2>Properties</h2> <dl class="properties"> <dt id="codeUnits" class="property"> <span class="name"><a href="../dart-core/String/codeUnits.html">codeUnits</a></span> <span class="signature">→ <a href="../dart-core/List-class.html">List</a><span class="signature"><<wbr><span class="type-parameter"><a href="../dart-core/int-class.html">int</a></span>></span></span> </dt> <dd> An unmodifiable list of the UTF-16 code units of this string. <div class="features"><span class="feature">no setter</span></div> </dd> <dt id="hashCode" class="property"> <span class="name"><a href="../dart-core/String/hashCode.html">hashCode</a></span> <span class="signature">→ <a href="../dart-core/int-class.html">int</a></span> </dt> <dd> A hash code derived from the code units of the string. <div class="features"><span class="feature">no setter</span><span class="feature">override</span></div> </dd> <dt id="isEmpty" class="property"> <span class="name"><a href="../dart-core/String/isEmpty.html">isEmpty</a></span> <span class="signature">→ <a href="../dart-core/bool-class.html">bool</a></span> </dt> <dd> Whether this string is empty. <div class="features"><span class="feature">no setter</span></div> </dd> <dt id="isNotEmpty" class="property"> <span class="name"><a href="../dart-core/String/isNotEmpty.html">isNotEmpty</a></span> <span class="signature">→ <a href="../dart-core/bool-class.html">bool</a></span> </dt> <dd> Whether this string is not empty. <div class="features"><span class="feature">no setter</span></div> </dd> <dt id="length" class="property"> <span class="name"><a href="../dart-core/String/length.html">length</a></span> <span class="signature">→ <a href="../dart-core/int-class.html">int</a></span> </dt> <dd> The length of the string. <div class="features"><span class="feature">no setter</span></div> </dd> <dt id="runes" class="property"> <span class="name"><a href="../dart-core/String/runes.html">runes</a></span> <span class="signature">→ <a href="../dart-core/Runes-class.html">Runes</a></span> </dt> <dd> An <a href="../dart-core/Iterable-class.html">Iterable</a> of Unicode code-points of this string. <div class="features"><span class="feature">no setter</span></div> </dd> <dt id="runtimeType" class="property inherited"> <span class="name"><a href="../dart-core/Object/runtimeType.html">runtimeType</a></span> <span class="signature">→ <a href="../dart-core/Type-class.html">Type</a></span> </dt> <dd class="inherited"> A representation of the runtime type of the object. <div class="features"><span class="feature">no setter</span><span class="feature">inherited</span></div> </dd> </dl> </section> <section class="summary offset-anchor" id="instance-methods"> <h2>Methods</h2> <dl class="callables"> <dt id="allMatches" class="callable inherited"> <span class="name"><a href="../dart-core/Pattern/allMatches.html">allMatches</a></span><span class="signature">(<wbr><span class="parameter" id="allMatches-param-string"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a></span> <span class="parameter-name">string</span>, [</span><span class="parameter" id="allMatches-param-start"><span class="type-annotation"><a href="../dart-core/int-class.html">int</a></span> <span class="parameter-name">start</span> = <span class="default-value">0</span></span>]) <span class="returntype parameter">→ <a href="../dart-core/Iterable-class.html">Iterable</a><span class="signature"><<wbr><span class="type-parameter"><a href="../dart-core/Match-class.html">Match</a></span>></span></span> </span> </dt> <dd class="inherited"> Matches this pattern against the string repeatedly. <div class="features"><span class="feature">inherited</span></div> </dd> <dt id="codeUnitAt" class="callable"> <span class="name"><a href="../dart-core/String/codeUnitAt.html">codeUnitAt</a></span><span class="signature">(<wbr><span class="parameter" id="codeUnitAt-param-index"><span class="type-annotation"><a href="../dart-core/int-class.html">int</a></span> <span class="parameter-name">index</span></span>) <span class="returntype parameter">→ <a href="../dart-core/int-class.html">int</a></span> </span> </dt> <dd> Returns the 16-bit UTF-16 code unit at the given <code>index</code>. </dd> <dt id="compareTo" class="callable"> <span class="name"><a href="../dart-core/String/compareTo.html">compareTo</a></span><span class="signature">(<wbr><span class="parameter" id="compareTo-param-other"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a></span> <span class="parameter-name">other</span></span>) <span class="returntype parameter">→ <a href="../dart-core/int-class.html">int</a></span> </span> </dt> <dd> Compares this string to <code>other</code>. <div class="features"><span class="feature">override</span></div> </dd> <dt id="contains" class="callable"> <span class="name"><a href="../dart-core/String/contains.html">contains</a></span><span class="signature">(<wbr><span class="parameter" id="contains-param-other"><span class="type-annotation"><a href="../dart-core/Pattern-class.html">Pattern</a></span> <span class="parameter-name">other</span>, [</span><span class="parameter" id="contains-param-startIndex"><span class="type-annotation"><a href="../dart-core/int-class.html">int</a></span> <span class="parameter-name">startIndex</span> = <span class="default-value">0</span></span>]) <span class="returntype parameter">→ <a href="../dart-core/bool-class.html">bool</a></span> </span> </dt> <dd> Whether this string contains a match of <code>other</code>. </dd> <dt id="endsWith" class="callable"> <span class="name"><a href="../dart-core/String/endsWith.html">endsWith</a></span><span class="signature">(<wbr><span class="parameter" id="endsWith-param-other"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a></span> <span class="parameter-name">other</span></span>) <span class="returntype parameter">→ <a href="../dart-core/bool-class.html">bool</a></span> </span> </dt> <dd> Whether this string ends with <code>other</code>. </dd> <dt id="indexOf" class="callable"> <span class="name"><a href="../dart-core/String/indexOf.html">indexOf</a></span><span class="signature">(<wbr><span class="parameter" id="indexOf-param-pattern"><span class="type-annotation"><a href="../dart-core/Pattern-class.html">Pattern</a></span> <span class="parameter-name">pattern</span>, [</span><span class="parameter" id="indexOf-param-start"><span class="type-annotation"><a href="../dart-core/int-class.html">int</a></span> <span class="parameter-name">start</span> = <span class="default-value">0</span></span>]) <span class="returntype parameter">→ <a href="../dart-core/int-class.html">int</a></span> </span> </dt> <dd> Returns the position of the first match of <code>pattern</code> in this string, starting at <code>start</code>, inclusive: </dd> <dt id="lastIndexOf" class="callable"> <span class="name"><a href="../dart-core/String/lastIndexOf.html">lastIndexOf</a></span><span class="signature">(<wbr><span class="parameter" id="lastIndexOf-param-pattern"><span class="type-annotation"><a href="../dart-core/Pattern-class.html">Pattern</a></span> <span class="parameter-name">pattern</span>, [</span><span class="parameter" id="lastIndexOf-param-start"><span class="type-annotation"><a href="../dart-core/int-class.html">int</a>?</span> <span class="parameter-name">start</span></span>]) <span class="returntype parameter">→ <a href="../dart-core/int-class.html">int</a></span> </span> </dt> <dd> The starting position of the last match <code>pattern</code> in this string. </dd> <dt id="matchAsPrefix" class="callable inherited"> <span class="name"><a href="../dart-core/Pattern/matchAsPrefix.html">matchAsPrefix</a></span><span class="signature">(<wbr><span class="parameter" id="matchAsPrefix-param-string"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a></span> <span class="parameter-name">string</span>, [</span><span class="parameter" id="matchAsPrefix-param-start"><span class="type-annotation"><a href="../dart-core/int-class.html">int</a></span> <span class="parameter-name">start</span> = <span class="default-value">0</span></span>]) <span class="returntype parameter">→ <a href="../dart-core/Match-class.html">Match</a>?</span> </span> </dt> <dd class="inherited"> Matches this pattern against the start of <code>string</code>. <div class="features"><span class="feature">inherited</span></div> </dd> <dt id="noSuchMethod" class="callable inherited"> <span class="name"><a href="../dart-core/Object/noSuchMethod.html">noSuchMethod</a></span><span class="signature">(<wbr><span class="parameter" id="noSuchMethod-param-invocation"><span class="type-annotation"><a href="../dart-core/Invocation-class.html">Invocation</a></span> <span class="parameter-name">invocation</span></span>) <span class="returntype parameter">→ dynamic</span> </span> </dt> <dd class="inherited"> Invoked when a nonexistent method or property is accessed. <div class="features"><span class="feature">inherited</span></div> </dd> <dt id="padLeft" class="callable"> <span class="name"><a href="../dart-core/String/padLeft.html">padLeft</a></span><span class="signature">(<wbr><span class="parameter" id="padLeft-param-width"><span class="type-annotation"><a href="../dart-core/int-class.html">int</a></span> <span class="parameter-name">width</span>, [</span><span class="parameter" id="padLeft-param-padding"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a></span> <span class="parameter-name">padding</span> = <span class="default-value">' '</span></span>]) <span class="returntype parameter">→ <a href="../dart-core/String-class.html">String</a></span> </span> </dt> <dd> Pads this string on the left if it is shorter than <code>width</code>. </dd> <dt id="padRight" class="callable"> <span class="name"><a href="../dart-core/String/padRight.html">padRight</a></span><span class="signature">(<wbr><span class="parameter" id="padRight-param-width"><span class="type-annotation"><a href="../dart-core/int-class.html">int</a></span> <span class="parameter-name">width</span>, [</span><span class="parameter" id="padRight-param-padding"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a></span> <span class="parameter-name">padding</span> = <span class="default-value">' '</span></span>]) <span class="returntype parameter">→ <a href="../dart-core/String-class.html">String</a></span> </span> </dt> <dd> Pads this string on the right if it is shorter than <code>width</code>. </dd> <dt id="replaceAll" class="callable"> <span class="name"><a href="../dart-core/String/replaceAll.html">replaceAll</a></span><span class="signature">(<wbr><span class="parameter" id="replaceAll-param-from"><span class="type-annotation"><a href="../dart-core/Pattern-class.html">Pattern</a></span> <span class="parameter-name">from</span>, </span><span class="parameter" id="replaceAll-param-replace"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a></span> <span class="parameter-name">replace</span></span>) <span class="returntype parameter">→ <a href="../dart-core/String-class.html">String</a></span> </span> </dt> <dd> Replaces all substrings that match <code>from</code> with <code>replace</code>. </dd> <dt id="replaceAllMapped" class="callable"> <span class="name"><a href="../dart-core/String/replaceAllMapped.html">replaceAllMapped</a></span><span class="signature">(<wbr><span class="parameter" id="replaceAllMapped-param-from"><span class="type-annotation"><a href="../dart-core/Pattern-class.html">Pattern</a></span> <span class="parameter-name">from</span>, </span><span class="parameter" id="replaceAllMapped-param-replace"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a></span> <span class="parameter-name">replace</span>(<span class="parameter" id="param-match"><span class="type-annotation"><a href="../dart-core/Match-class.html">Match</a></span> <span class="parameter-name">match</span></span>)</span>) <span class="returntype parameter">→ <a href="../dart-core/String-class.html">String</a></span> </span> </dt> <dd> Replace all substrings that match <code>from</code> by a computed string. </dd> <dt id="replaceFirst" class="callable"> <span class="name"><a href="../dart-core/String/replaceFirst.html">replaceFirst</a></span><span class="signature">(<wbr><span class="parameter" id="replaceFirst-param-from"><span class="type-annotation"><a href="../dart-core/Pattern-class.html">Pattern</a></span> <span class="parameter-name">from</span>, </span><span class="parameter" id="replaceFirst-param-to"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a></span> <span class="parameter-name">to</span>, [</span><span class="parameter" id="replaceFirst-param-startIndex"><span class="type-annotation"><a href="../dart-core/int-class.html">int</a></span> <span class="parameter-name">startIndex</span> = <span class="default-value">0</span></span>]) <span class="returntype parameter">→ <a href="../dart-core/String-class.html">String</a></span> </span> </dt> <dd> Creates a new string with the first occurrence of <code>from</code> replaced by <code>to</code>. </dd> <dt id="replaceFirstMapped" class="callable"> <span class="name"><a href="../dart-core/String/replaceFirstMapped.html">replaceFirstMapped</a></span><span class="signature">(<wbr><span class="parameter" id="replaceFirstMapped-param-from"><span class="type-annotation"><a href="../dart-core/Pattern-class.html">Pattern</a></span> <span class="parameter-name">from</span>, </span><span class="parameter" id="replaceFirstMapped-param-replace"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a></span> <span class="parameter-name">replace</span>(<span class="parameter" id="replace-param-match"><span class="type-annotation"><a href="../dart-core/Match-class.html">Match</a></span> <span class="parameter-name">match</span></span>), [</span><span class="parameter" id="replaceFirstMapped-param-startIndex"><span class="type-annotation"><a href="../dart-core/int-class.html">int</a></span> <span class="parameter-name">startIndex</span> = <span class="default-value">0</span></span>]) <span class="returntype parameter">→ <a href="../dart-core/String-class.html">String</a></span> </span> </dt> <dd> Replace the first occurrence of <code>from</code> in this string. </dd> <dt id="replaceRange" class="callable"> <span class="name"><a href="../dart-core/String/replaceRange.html">replaceRange</a></span><span class="signature">(<wbr><span class="parameter" id="replaceRange-param-start"><span class="type-annotation"><a href="../dart-core/int-class.html">int</a></span> <span class="parameter-name">start</span>, </span><span class="parameter" id="replaceRange-param-end"><span class="type-annotation"><a href="../dart-core/int-class.html">int</a>?</span> <span class="parameter-name">end</span>, </span><span class="parameter" id="replaceRange-param-replacement"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a></span> <span class="parameter-name">replacement</span></span>) <span class="returntype parameter">→ <a href="../dart-core/String-class.html">String</a></span> </span> </dt> <dd> Replaces the substring from <code>start</code> to <code>end</code> with <code>replacement</code>. </dd> <dt id="split" class="callable"> <span class="name"><a href="../dart-core/String/split.html">split</a></span><span class="signature">(<wbr><span class="parameter" id="split-param-pattern"><span class="type-annotation"><a href="../dart-core/Pattern-class.html">Pattern</a></span> <span class="parameter-name">pattern</span></span>) <span class="returntype parameter">→ <a href="../dart-core/List-class.html">List</a><span class="signature"><<wbr><span class="type-parameter"><a href="../dart-core/String-class.html">String</a></span>></span></span> </span> </dt> <dd> Splits the string at matches of <code>pattern</code> and returns a list of substrings. </dd> <dt id="splitMapJoin" class="callable"> <span class="name"><a href="../dart-core/String/splitMapJoin.html">splitMapJoin</a></span><span class="signature">(<wbr><span class="parameter" id="splitMapJoin-param-pattern"><span class="type-annotation"><a href="../dart-core/Pattern-class.html">Pattern</a></span> <span class="parameter-name">pattern</span>, {</span><span class="parameter" id="splitMapJoin-param-onMatch"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a></span> <span class="parameter-name">onMatch</span>(<span class="parameter" id="param-"><span class="type-annotation"><a href="../dart-core/Match-class.html">Match</a></span></span>)?, </span><span class="parameter" id="splitMapJoin-param-onNonMatch"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a></span> <span class="parameter-name">onNonMatch</span>(<span class="parameter" id="param-"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a></span></span>)?</span>}) <span class="returntype parameter">→ <a href="../dart-core/String-class.html">String</a></span> </span> </dt> <dd> Splits the string, converts its parts, and combines them into a new string. </dd> <dt id="startsWith" class="callable"> <span class="name"><a href="../dart-core/String/startsWith.html">startsWith</a></span><span class="signature">(<wbr><span class="parameter" id="startsWith-param-pattern"><span class="type-annotation"><a href="../dart-core/Pattern-class.html">Pattern</a></span> <span class="parameter-name">pattern</span>, [</span><span class="parameter" id="startsWith-param-index"><span class="type-annotation"><a href="../dart-core/int-class.html">int</a></span> <span class="parameter-name">index</span> = <span class="default-value">0</span></span>]) <span class="returntype parameter">→ <a href="../dart-core/bool-class.html">bool</a></span> </span> </dt> <dd> Whether this string starts with a match of <code>pattern</code>. </dd> <dt id="substring" class="callable"> <span class="name"><a href="../dart-core/String/substring.html">substring</a></span><span class="signature">(<wbr><span class="parameter" id="substring-param-start"><span class="type-annotation"><a href="../dart-core/int-class.html">int</a></span> <span class="parameter-name">start</span>, [</span><span class="parameter" id="substring-param-end"><span class="type-annotation"><a href="../dart-core/int-class.html">int</a>?</span> <span class="parameter-name">end</span></span>]) <span class="returntype parameter">→ <a href="../dart-core/String-class.html">String</a></span> </span> </dt> <dd> The substring of this string from <code>start</code>, inclusive, to <code>end</code>, exclusive. </dd> <dt id="toLowerCase" class="callable"> <span class="name"><a href="../dart-core/String/toLowerCase.html">toLowerCase</a></span><span class="signature">(<wbr>) <span class="returntype parameter">→ <a href="../dart-core/String-class.html">String</a></span> </span> </dt> <dd> Converts all characters in this string to lower case. </dd> <dt id="toString" class="callable inherited"> <span class="name"><a href="../dart-core/Object/toString.html">toString</a></span><span class="signature">(<wbr>) <span class="returntype parameter">→ <a href="../dart-core/String-class.html">String</a></span> </span> </dt> <dd class="inherited"> A string representation of this object. <div class="features"><span class="feature">inherited</span></div> </dd> <dt id="toUpperCase" class="callable"> <span class="name"><a href="../dart-core/String/toUpperCase.html">toUpperCase</a></span><span class="signature">(<wbr>) <span class="returntype parameter">→ <a href="../dart-core/String-class.html">String</a></span> </span> </dt> <dd> Converts all characters in this string to upper case. </dd> <dt id="trim" class="callable"> <span class="name"><a href="../dart-core/String/trim.html">trim</a></span><span class="signature">(<wbr>) <span class="returntype parameter">→ <a href="../dart-core/String-class.html">String</a></span> </span> </dt> <dd> The string without any leading and trailing whitespace. </dd> <dt id="trimLeft" class="callable"> <span class="name"><a href="../dart-core/String/trimLeft.html">trimLeft</a></span><span class="signature">(<wbr>) <span class="returntype parameter">→ <a href="../dart-core/String-class.html">String</a></span> </span> </dt> <dd> The string without any leading whitespace. </dd> <dt id="trimRight" class="callable"> <span class="name"><a href="../dart-core/String/trimRight.html">trimRight</a></span><span class="signature">(<wbr>) <span class="returntype parameter">→ <a href="../dart-core/String-class.html">String</a></span> </span> </dt> <dd> The string without any trailing whitespace. </dd> </dl> </section> <section class="summary offset-anchor" id="operators"> <h2>Operators</h2> <dl class="callables"> <dt id="operator *" class="callable"> <span class="name"><a href="../dart-core/String/operator_multiply.html">operator *</a></span><span class="signature">(<wbr><span class="parameter" id="*-param-times"><span class="type-annotation"><a href="../dart-core/int-class.html">int</a></span> <span class="parameter-name">times</span></span>) <span class="returntype parameter">→ <a href="../dart-core/String-class.html">String</a></span> </span> </dt> <dd> Creates a new string by concatenating this string with itself a number of times. </dd> <dt id="operator +" class="callable"> <span class="name"><a href="../dart-core/String/operator_plus.html">operator +</a></span><span class="signature">(<wbr><span class="parameter" id="+-param-other"><span class="type-annotation"><a href="../dart-core/String-class.html">String</a></span> <span class="parameter-name">other</span></span>) <span class="returntype parameter">→ <a href="../dart-core/String-class.html">String</a></span> </span> </dt> <dd> Creates a new string by concatenating this string with <code>other</code>. </dd> <dt id="operator ==" class="callable"> <span class="name"><a href="../dart-core/String/operator_equals.html">operator ==</a></span><span class="signature">(<wbr><span class="parameter" id="==-param-other"><span class="type-annotation"><a href="../dart-core/Object-class.html">Object</a></span> <span class="parameter-name">other</span></span>) <span class="returntype parameter">→ <a href="../dart-core/bool-class.html">bool</a></span> </span> </dt> <dd> Whether <code>other</code> is a <code>String</code> with the same sequence of code units. <div class="features"><span class="feature">override</span></div> </dd> <dt id="operator []" class="callable"> <span class="name"><a href="../dart-core/String/operator_get.html">operator []</a></span><span class="signature">(<wbr><span class="parameter" id="[]-param-index"><span class="type-annotation"><a href="../dart-core/int-class.html">int</a></span> <span class="parameter-name">index</span></span>) <span class="returntype parameter">→ <a href="../dart-core/String-class.html">String</a></span> </span> </dt> <dd> The character (as a single-code-unit <a href="../dart-core/String-class.html">String</a>) at the given <code>index</code>. </dd> </dl> </section> </div> <!-- /.main-content --> <div id="dartdoc-sidebar-left" class="sidebar sidebar-offcanvas-left"> <!-- The search input and breadcrumbs below are only responsively visible at low resolutions. --> <header id="header-search-sidebar" class="hidden-l"> <form class="search-sidebar" role="search"> <input type="text" id="search-sidebar" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search..."> </form> </header> <ol class="breadcrumbs gt-separated dark hidden-l" id="sidebar-nav"> <li><a href="../index.html">Dart</a></li> <li><a href="../dart-core/dart-core-library.html">dart:core</a></li> <li class="self-crumb">String class</li> </ol> <h5>dart:core library</h5> <div id="dartdoc-sidebar-left-content"></div> </div> <div id="dartdoc-sidebar-right" class="sidebar sidebar-offcanvas-right"> </div><!--/.sidebar-offcanvas--> </main> <footer> <span class="no-break"> Dart 3.5.4 </span> <span class="glue-footer"> <span class="no-break"> | <a href="https://dart.dev/terms" title="Terms of use">Terms</a> </span> <span class="no-break"> | <a href="https://policies.google.com/privacy" target="_blank" rel="noopener" title="Privacy policy" class="no-automatic-external">Privacy</a> </span> <span class="no-break"> | <a href="https://dart.dev/security" title="Security philosophy and practices">Security</a> </span> <div class="copyright" style="font-size: 0.9em; color: darkgrey; margin-top: 0.5em;"> Except as otherwise noted, this site is licensed under a <a style="color: darkgrey;" href="https://creativecommons.org/licenses/by/4.0/"> Creative Commons Attribution 4.0 International License</a> and code samples are licensed under the <a style="color: darkgrey;" href="https://opensource.org/licenses/BSD-3-Clause" class="no-automatic-external"> 3-Clause BSD License</a> </div> </span> </footer> <script src="../static-assets/highlight.pack.js?v1"></script> <script src="../static-assets/docs.dart.js"></script> <button aria-hidden="true" class="glue-footer__link glue-cookie-notification-bar-control"> Cookies management controls </button> <script src="https://www.gstatic.com/glue/cookienotificationbar/cookienotificationbar.min.js" data-glue-cookie-notification-bar-category="2B"> </script> </body> </html>