String Extension
capitalizeFirstLetter
Capitalizes the first letter of the string.
String example = "flutter and dart";
print(example.capitalizeFirstLetter); // Output: "Flutter and dart"
String example = "flutter and dart";
print(example.capitalizeFirstLetter); // Output: "Flutter and dart"
toPascalCase
Convert the string to Pascal Case.
String example = "flutter and dart";
print(example.toPascalCase); // Output: "FlutterAndDart"
String example = "flutter and dart";
print(example.toPascalCase); // Output: "FlutterAndDart"
toCamelCase
Convert the string to Camel Case.
String example = "flutter and dart";
print(example.toCamelCase); // Output: "flutterAndDart"
String example = "flutter and dart";
print(example.toCamelCase); // Output: "flutterAndDart"
toTitleCase
Convert the string to Title Case.
String example = "flutter and dart";
print(example.toTitleCase); // Output: "Flutter And Dart"
String example = "flutter and dart";
print(example.toTitleCase); // Output: "Flutter And Dart"
toTitle
Similar to toTitleCase but ignores - and _.
String example = "flutter-and-dart";
print(example.toTitle); // Output: "Flutter-And-Dart"
String example = "flutter-and-dart";
print(example.toTitle); // Output: "Flutter-And-Dart"
shouldIgnoreCapitalization
Check if the string should ignore capitalization.
String example = "1flutter";
print(example.shouldIgnoreCapitalization); // Output: true
String example = "1flutter";
print(example.shouldIgnoreCapitalization); // Output: true
removeEmptyLines
Removes empty lines from the string.
String example = "line1\n\nline2";
print(example.removeEmptyLines); // Output: "line1\nline2"
String example = "line1\n\nline2";
print(example.removeEmptyLines); // Output: "line1\nline2"
toOneLine
Convert the string to a single line by replacing newlines with spaces.
String example = "line1\nline2";
print(example.toOneLine); // Output: "line1 line2"
String example = "line1\nline2";
print(example.toOneLine); // Output: "line1 line2"
removeWhiteSpaces
Removes all space from the string.
String example = " flutter ";
print(example.removeWhiteSpaces); // Output: "flutter"
String example = " flutter ";
print(example.removeWhiteSpaces); // Output: "flutter"
isEmptyOrNull
Check if the string is empty or null.
String? example = null;
print(example.isEmptyOrNull); // Output: true
String? example = null;
print(example.isEmptyOrNull); // Output: true
isNotEmptyOrNull
Check if the string is not empty or null.
String? example = "flutter";
print(example.isNotEmptyOrNull); // Output: true
String? example = "flutter";
print(example.isNotEmptyOrNull); // Output: true
isPalindrom
Check if the string is a palindrome.
String? example = "radar";
print(example.isPalindrom); // Output: true
String? example = "radar";
print(example.isPalindrom); // Output: true
isAlphanumeric
Check if the string is alphanumeric.
String? example = "abc123";
print(example.isAlphanumeric); // Output: true
String? example = "abc123";
print(example.isAlphanumeric); // Output: true
startsWithNumber
Check if the string starts with a number.
String? example = "1flutter";
print(example.startsWithNumber); // Output: true
String? example = "1flutter";
print(example.startsWithNumber); // Output: true
containsDigits
Check if the string contains any digits.
String? example = "abc123";
print(example.containsDigits); // Output: true
String? example = "abc123";
print(example.containsDigits); // Output: true
isValidUsername
Check if the string is a valid username.
String example = "username_123";
print(example.isValidUsername); // Output: true
String example = "username_123";
print(example.isValidUsername); // Output: true
isValidCurrency
Check if the string is a valid currency.
String example = "$100.00 USD";
print(example.isValidCurrency); // Output: true
String example = "$100.00 USD";
print(example.isValidCurrency); // Output: true
isValidPhoneNumber
Check if the string is a valid phone number.
String example = "+1 123-456-7890";
print(example.isValidPhoneNumber); // Output: true
String example = "+1 123-456-7890";
print(example.isValidPhoneNumber); // Output: true
isValidEmail
Check if the string is a valid email address.
String example = "email@example.com";
print(example.isValidEmail); // Output: true
String example = "email@example.com";
print(example.isValidEmail); // Output: true
isValidHTML
Check if the string is an HTML file.
String example = "index.html";
print(example.isValidHTML); // Output: true
String example = "index.html";
print(example.isValidHTML); // Output: true
isValidIp4
Check if the string is a valid IPv4 address.
String example = "192.168.1.1";
print(example.isValidIp4); // Output: true
String example = "192.168.1.1";
print(example.isValidIp4); // Output: true
isValidIp6
Check if the string is a valid IPv6 address.
String example = "FE80::8329";
print(example.isValidIp6); // Output: true
String example = "FE80::8329";
print(example.isValidIp6); // Output: true
isValidUrl
Check if the string is a valid URL.
String example = "https://www.example.com";
print(example.isValidUrl); // Output: true
String example = "https://www.example.com";
print(example.isValidUrl); // Output: true
isValidVideo
Check if the string is a video file.
String example = "video.mp4";
print(example.isValidVideo); // Output: true
String example = "video.mp4";
print(example.isValidVideo); // Output: true
isValidAudio
Check if the string is an audio file.
String example = "audio.mp3";
print(example.isValidAudio); // Output: true
String example = "audio.mp3";
print(example.isValidAudio); // Output: true
isValidImage
Check if the string is an image file.
String example = "image.jpg";
print(example.isValidImage); // Output: true
String example = "image.jpg";
print(example.isValidImage); // Output: true
isValidSVG
Check if the string is an SVG file.
String example = "image.svg";
print(example.isValidSVG); // Output: true
String example = "image.svg";
print(example.isValidSVG); // Output: true
hasMatch
Check if the string matches a given regular expression pattern.
String example = "123";
print(example.hasMatch(r'^\d+$')); // Output: true
String example = "123";
print(example.hasMatch(r'^\d+$')); // Output: true
isNumeric
Check if the string is numeric.
String example = "123";
print(example.isNumeric); // Output: true
String example = "123";
print(example.isNumeric); // Output: true
isAlphabet
Check if the string consists only of alphabets.
String example = "abc";
print(example.isAlphabet); // Output: true
String example = "abc";
print(example.isAlphabet); // Output: true
hasCapitalLetter
Check if the string contains at least one capital letter.
String example = "Abc";
print(example.hasCapitalLetter); // Output: true
String example = "Abc";
print(example.hasCapitalLetter); // Output: true
isBool
Check if the string is a boolean value.
String example = "true";
print(example.isBool); // Output: true
String example = "true";
print(example.isBool); // Output: true
removeWhiteSpaces
Removes all space from the string.
String example = "Hello World";
print(example.removeWhiteSpaces); // Output: HelloWorld
String example = "Hello World";
print(example.removeWhiteSpaces); // Output: HelloWorld
textSize
Returns the size of the text using TextPainter.
String example = "Hello";
print(example.textSize); // Output: Size(width, height)
String example = "Hello";
print(example.textSize); // Output: Size(width, height)
wrapString
Adds a new line to the string after a specified number of words.
String example = "Hi, my name is";
print(example.wrapString(2)); // Output: "Hi, my\nname is"
String example = "Hi, my name is";
print(example.wrapString(2)); // Output: "Hi, my\nname is"
equalsIgnoreCase
Compares two strings for equality, ignoring case.
String example = "Hello";
print(example.equalsIgnoreCase("hello")); // Output: true
String example = "Hello";
print(example.equalsIgnoreCase("hello")); // Output: true
removeSurrounding
Removes a specified delimiter from both ends of the string, if present.
String example = "[Hello]";
print(example.removeSurrounding("[").removeSurrounding("]")); // Output: Hello
String example = "[Hello]";
print(example.removeSurrounding("[").removeSurrounding("]")); // Output: Hello
replaceAfter
Replaces part of the string after the first occurrence of a given delimiter.
String example = "Hello, World";
print(example.replaceAfter(",", " everyone")); // Output: Hello, everyone
String example = "Hello, World";
print(example.replaceAfter(",", " everyone")); // Output: Hello, everyone
replaceBefore
Replaces part of the string before the first occurrence of a given delimiter.
String example = "Hello, World";
print(example.replaceBefore(",", "Hi")); // Output: Hi, World
String example = "Hello, World";
print(example.replaceBefore(",", "Hi")); // Output: Hi, World
anyChar
Returns true if any character in the string matches a given predicate function.
String example = "abc";
print(example.anyChar((char) => char == 'a')); // Output: true
String example = "abc";
print(example.anyChar((char) => char == 'a')); // Output: true
orEmpty
Returns the string if it is not null, or an empty string otherwise.
String? example = null;
print(example.orEmpty); // Output: ""
String? example = null;
print(example.orEmpty); // Output: ""
ifEmpty
Execute a given action if the string is empty.
String example = "";
example.ifEmpty(() => print("String is empty")); // Output: String is empty
String example = "";
example.ifEmpty(() => print("String is empty")); // Output: String is empty
lastIndex
Returns the last character in the string.
String example = "abc";
print(example.lastIndex); // Output: "c"
String example = "abc";
print(example.lastIndex); // Output: "c"
tryToNum
, tryToDouble
, tryToInt
, toNum
, toDouble
, toInt
Various methods for parsing the string into numbers.
String example = "123";
print(example.tryToNum); // Output: 123
String example = "123";
print(example.tryToNum); // Output: 123
isNotBlank
Check if the string is neither null, empty, nor made solely of whitespace characters.
String example = " ";
print(example.isNotBlank); // Output: false
String example = " ";
print(example.isNotBlank); // Output: false
toCharArray
Convert the string to a list of characters.
String example = "abc";
print(example.toCharArray()); // Output: ["a", "b", "c"]
String example = "abc";
print(example.toCharArray()); // Output: ["a", "b", "c"]
insert
Insert a given string at a specified index.
String example = "abc";
print(example.insert(1, "d")); // Output: "adbc"
String example = "abc";
print(example.insert(1, "d")); // Output: "adbc"
isNullOrWhiteSpace
Check if the string is null, empty, or made solely of whitespace characters.
String example = " ";
print(example.isNullOrWhiteSpace); // Output: true
String example = " ";
print(example.isNullOrWhiteSpace); // Output: true
limitFromEnd
, limitFromStart
Limits the string to a specified length from either the start or the end.
String example = "abcdefgh";
print(example.limitFromEnd(3)); // Output: "fgh"
String example = "abcdefgh";
print(example.limitFromEnd(3)); // Output: "fgh"
asBool
Convert the string to a boolean value based on certain conditions.
String example = "true";
print(example.asBool); // Output: true
String example = "true";
print(example.asBool); // Output: true