Str class abstract final

String helpers with Laravel's Str semantics (BLUEPRINT_V2 §7.12).

Str.slug('Hello World!');          // hello-world
Str.snake('emailVerifiedAt');      // email_verified_at
Str.studly('user_profile');        // UserProfile
Str.plural('category');            // categories
Str.limit('The quick brown fox', 9); // The quick...

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

after(String subject, String search) → String
What follows the first search in subject, or all of it without one.
afterLast(String subject, String search) → String
What follows the last search in subject, or all of it without one.
ascii(String value) → String
Replaces common Latin accented letters with ASCII (Str::ascii, for Latin scripts; other characters are kept).
before(String subject, String search) → String
What precedes the first search in subject, or all of it without one.
beforeLast(String subject, String search) → String
What precedes the last search in subject, or all of it without one.
between(String subject, String from, String to) → String
The part between the first from and the last to.
camel(String value) → String
foo_bar → fooBar.
contains(String haystack, Object needles, {bool ignoreCase = false}) → bool
Whether haystack contains any of needles (a String or an Iterable<String>).
containsAll(String haystack, Iterable<String> needles, {bool ignoreCase = false}) → bool
Whether haystack contains every needle.
endsWith(String haystack, Object needles) → bool
Whether haystack ends with a string, or with one of a list.
finish(String value, String cap) → String
Suffixes cap unless already there (Str::finish).
headline(String value) → String
emailNotificationSent / email_notification_sent → Email Notification Sent.
isAscii(String value) → bool
Whether value is 7-bit ASCII only.
isJson(String value) → bool
Whether value is valid JSON.
isUlid(String value) → bool
Whether value is a ULID.
isUuid(String value) → bool
Whether value is a UUID.
kebab(String value) → String
fooBar → foo-bar.
lcfirst(String value) → String
value with its first character lower case.
limit(String value, [int limit = 100, String end = '...']) → String
Truncates to limit characters plus end (Str::limit).
mask(String value, String character, int index, [int? length]) → String
Replaces length characters from index with character (Str::mask('taylor@example.com', '*', 3)). Negative index counts from the end.
padBoth(String value, int length, [String pad = ' ']) → String
value padded on both sides to length with pad.
padLeft(String value, int length, [String pad = ' ']) → String
value padded on the left to length with pad.
padRight(String value, int length, [String pad = ' ']) → String
value padded on the right to length with pad.
plural(String value, [num count = 2]) → String
English plural of value (singular when count is 1), keeping its case (Str::plural).
pluralStudly(String value, [num count = 2]) → String
UserProfile → UserProfiles: pluralizes the last studly word.
random([int length = 16]) → String
Cryptographically secure alphanumeric string (Str::random).
replaceFirst(String search, String replace, String subject) → String
subject with its first search replaced.
replaceLast(String search, String replace, String subject) → String
subject with its last search replaced.
singular(String value) → String
English singular of value (Str::singular).
slug(String value, {String separator = '-'}) → String
URL slug: lower case ASCII, separators collapsed, @ → at.
snake(String value, [String delimiter = '_']) → String
fooBar / Foo Bar → foo_bar (Laravel Str::snake).
squish(String value) → String
Trims and collapses inner whitespace (Str::squish).
start(String value, String prefix) → String
Prefixes prefix unless already there (Str::start).
startsWith(String haystack, Object needles) → bool
Whether haystack starts with a string, or with one of a list.
studly(String value) → String
foo_bar / foo-bar / foo bar → FooBar.
title(String value) → String
hello world → Hello World.
trimChars(String value, String chars) → String
value without the characters of chars at either end.
ucfirst(String value) → String
value with its first character upper case.
ucwords(String value) → String
Upper-cases the first letter of every whitespace separated word.
ulid([DateTime? time]) → String
Sortable ULID (26 Crockford base32 characters).
uuid() → String
Random UUID v4.
wordCount(String value) → int
The number of words in value.
words(String value, [int count = 100, String end = '...']) → String
Keeps the first count words plus end (Str::words).