StringView class

A non-owning, zero-allocation reference to a string or a contiguous substring.

In the C++ STL, this matches the behavior of std::string_view. It provides high-performance read-only operations on text sequences without dynamically allocating new string memory under the hood.

Constructors

StringView(String _string)
Creates a StringView from an entire String.
StringView.substring(String _string, int _start, int _end)
Creates a StringView from a specific segment of a String.

Properties

hashCode int
The hash code for this object.
no setteroverride
isEmpty bool
Returns true if the string view is empty.
no setter
isNotEmpty bool
Returns true if the string view is not empty.
no setter
length int
Returns the length of the string view.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

contains(String pattern, [int start = 0]) bool
Checks if this string view contains the pattern.
endsWith(String pattern) bool
Checks whether the string view ends with the given pattern.
indexOf(String pattern, [int start = 0]) int
Returns the position of the first match of pattern in this view, starting the search at start.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
startsWith(String pattern) bool
Checks whether the string view begins with the given pattern.
substring(int start, [int? end]) StringView
Returns a new StringView spanning a portion of this view.
toString() String
Instantiates a standard Dart String containing the precise view segment. Note: This performs an $O(N)$ memory allocation!
override
trim() StringView
Trims leading and trailing whitespace, returning a new tightly-bound StringView.

Operators

operator ==(Object other) bool
The equality operator.
override
operator [](int index) String
Returns the character at the given index.