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
Converts 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
Converts 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
Converts 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
Checks if the string should ignore capitalization.
String example = "1flutter";
print(example.shouldIgnoreCapitalization); // Output: trueString example = "1flutter";
print(example.shouldIgnoreCapitalization); // Output: trueremoveEmptyLines
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
Converts 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 white spaces from the string.
String example = " flutter ";
print(example.removeWhiteSpaces); // Output: "flutter"String example = " flutter ";
print(example.removeWhiteSpaces); // Output: "flutter"isEmptyOrNull
Checks if the string is empty or null.
String? example = null;
print(example.isEmptyOrNull); // Output: trueString? example = null;
print(example.isEmptyOrNull); // Output: trueisNotEmptyOrNull
Checks if the string is not empty or null.
String? example = "flutter";
print(example.isNotEmptyOrNull); // Output: trueString? example = "flutter";
print(example.isNotEmptyOrNull); // Output: trueisPalindrom
Checks if the string is a palindrome.
String? example = "radar";
print(example.isPalindrom); // Output: trueString? example = "radar";
print(example.isPalindrom); // Output: trueisAlphanumeric
Checks if the string is alphanumeric.
String? example = "abc123";
print(example.isAlphanumeric); // Output: trueString? example = "abc123";
print(example.isAlphanumeric); // Output: truestartsWithNumber
Checks if the string starts with a number.
String? example = "1flutter";
print(example.startsWithNumber); // Output: trueString? example = "1flutter";
print(example.startsWithNumber); // Output: truecontainsDigits
Checks if the string contains any digits.
String? example = "abc123";
print(example.containsDigits); // Output: trueString? example = "abc123";
print(example.containsDigits); // Output: trueisValidUsername
Checks if the string is a valid username.
String example = "username_123";
print(example.isValidUsername); // Output: trueString example = "username_123";
print(example.isValidUsername); // Output: trueisValidCurrency
Checks if the string is a valid currency.
String example = "$100.00 USD";
print(example.isValidCurrency); // Output: trueString example = "$100.00 USD";
print(example.isValidCurrency); // Output: trueisValidPhoneNumber
Checks if the string is a valid phone number.
String example = "+1 123-456-7890";
print(example.isValidPhoneNumber); // Output: trueString example = "+1 123-456-7890";
print(example.isValidPhoneNumber); // Output: trueisValidEmail
Checks if the string is a valid email address.
String example = "email@example.com";
print(example.isValidEmail); // Output: trueString example = "email@example.com";
print(example.isValidEmail); // Output: trueisValidHTML
Checks if the string is an HTML file.
String example = "index.html";
print(example.isValidHTML); // Output: trueString example = "index.html";
print(example.isValidHTML); // Output: trueisValidIp4
Checks if the string is a valid IPv4 address.
String example = "192.168.1.1";
print(example.isValidIp4); // Output: trueString example = "192.168.1.1";
print(example.isValidIp4); // Output: trueisValidIp6
Checks if the string is a valid IPv6 address.
String example = "FE80::8329";
print(example.isValidIp6); // Output: trueString example = "FE80::8329";
print(example.isValidIp6); // Output: trueisValidUrl
Checks if the string is a valid URL.
String example = "https://www.example.com";
print(example.isValidUrl); // Output: trueString example = "https://www.example.com";
print(example.isValidUrl); // Output: trueisValidVideo
Checks if the string is a video file.
String example = "video.mp4";
print(example.isValidVideo); // Output: trueString example = "video.mp4";
print(example.isValidVideo); // Output: trueisValidAudio
Checks if the string is an audio file.
String example = "audio.mp3";
print(example.isValidAudio); // Output: trueString example = "audio.mp3";
print(example.isValidAudio); // Output: trueisValidImage
Checks if the string is an image file.
String example = "image.jpg";
print(example.isValidImage); // Output: trueString example = "image.jpg";
print(example.isValidImage); // Output: trueisValidSVG
Checks if the string is an SVG file.
String example = "image.svg";
print(example.isValidSVG); // Output: trueString example = "image.svg";
print(example.isValidSVG); // Output: truehasMatch
Checks if the string matches a given regular expression pattern.
String example = "123";
print(example.hasMatch(r'^\d+$')); // Output: trueString example = "123";
print(example.hasMatch(r'^\d+$')); // Output: trueisNumeric
Checks if the string is numeric.
String example = "123";
print(example.isNumeric); // Output: trueString example = "123";
print(example.isNumeric); // Output: trueisAlphabet
Checks if the string consists only of alphabets.
String example = "abc";
print(example.isAlphabet); // Output: trueString example = "abc";
print(example.isAlphabet); // Output: truehasCapitalLetter
Checks if the string contains at least one capital letter.
String example = "Abc";
print(example.hasCapitalLetter); // Output: trueString example = "Abc";
print(example.hasCapitalLetter); // Output: trueisBool
Checks if the string is a boolean value.
String example = "true";
print(example.isBool); // Output: trueString example = "true";
print(example.isBool); // Output: trueremoveWhiteSpaces
Removes all white spaces from the string.
String example = "Hello World";
print(example.removeWhiteSpaces); // Output: HelloWorldString example = "Hello World";
print(example.removeWhiteSpaces); // Output: HelloWorldtextSize
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: trueString example = "Hello";
print(example.equalsIgnoreCase("hello")); // Output: trueremoveSurrounding
Removes a specified delimiter from both ends of the string, if present.
String example = "[Hello]";
print(example.removeSurrounding("[").removeSurrounding("]")); // Output: HelloString example = "[Hello]";
print(example.removeSurrounding("[").removeSurrounding("]")); // Output: HelloreplaceAfter
Replaces part of the string after the first occurrence of a given delimiter.
String example = "Hello, World";
print(example.replaceAfter(",", " everyone")); // Output: Hello, everyoneString example = "Hello, World";
print(example.replaceAfter(",", " everyone")); // Output: Hello, everyonereplaceBefore
Replaces part of the string before the first occurrence of a given delimiter.
String example = "Hello, World";
print(example.replaceBefore(",", "Hi")); // Output: Hi, WorldString example = "Hello, World";
print(example.replaceBefore(",", "Hi")); // Output: Hi, WorldanyChar
Returns true if any character in the string matches a given predicate function.
String example = "abc";
print(example.anyChar((char) => char == 'a')); // Output: trueString example = "abc";
print(example.anyChar((char) => char == 'a')); // Output: trueorEmpty
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
Executes a given action if the string is empty.
String example = "";
example.ifEmpty(() => print("String is empty")); // Output: String is emptyString example = "";
example.ifEmpty(() => print("String is empty")); // Output: String is emptylastIndex
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: 123String example = "123";
print(example.tryToNum); // Output: 123isNotBlank
Checks if the string is neither null, empty, nor made solely of whitespace characters.
String example = " ";
print(example.isNotBlank); // Output: falseString example = " ";
print(example.isNotBlank); // Output: falsetoCharArray
Converts 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
Checks if the string is null, empty, or made solely of whitespace characters.
String example = " ";
print(example.isNullOrWhiteSpace); // Output: trueString example = " ";
print(example.isNullOrWhiteSpace); // Output: truelimitFromEnd, 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
Converts the string to a boolean value based on certain conditions.
String example = "true";
print(example.asBool); // Output: trueString example = "true";
print(example.asBool); // Output: true