string_extensions 0.3.2 string_extensions: ^0.3.2 copied to clipboard
Useful String extensions to save you time in production. Feel free to contribute with PR.
Current Methods #
- You can use
>, >=, <, <=
operators, to compareString
lengths.
String s1 = 'esentis';
String s2 = 'dev';
print(s1 > s2); // prints true
print(s1 >= s2); // prints true
print(s1 < s2); // prints false
print(s1 <= s2); // prints false
- isGuid()
String foo = '6d64-4396-8547-1ec1b86e081e'
bool isGuid = foo.isGuid() // returns false
- isUrl()
String foo = 'esentis';
bool isUrl = foo.isUrl() // 'false';
- isDate()
String foo = 'esentis';
bool isDate = foo.isDate() // 'false';
- isMail()
String foo = 'esentis@esentis.com'
bool isMail = foo.isMail() // returns true
String foo = 'esentis@esentis'
bool isMail = foo.isMail() // returns false
- isIpv4()
String foo = '192.168.1.14';
bool isIpv4 = foo.isIpv4(); // returns true
String foo = '192.168.1.14.150.1225';
bool isIpv4 = foo.isIpv4(); // returns false
- isIpv6()
String foo = '2001:0db8:85a3:0000:0000:8a2e:0370:7334';
bool isIpv6 = foo.isIpv6(); // returns true
String foo = '92.168.1.14';
bool isIpv6 = foo.isIpv6(); // returns false
- isNumber()
String foo = '44';
bool isNumber = foo.isNumber(); // returns true
String foo = '92.168.1.14';
bool isNumber = foo.isNumber(); // returns false
- isIn()
String foo = '6d64-4396-8547-1ec1b86e081e';
var iterable = ['fff','gasd'];
bool isIn = foo.isIn(iterable) // returns false
- toStringArray()
String foo = 'abracadabra';
List<String> fooArray = foo.toStringArray(); // returns '[a,b,r,a,c,a,d,a,b,r,a]'
- toCamelCase()
String foo = 'Find max of array';
String camelCase = foo.toCamelCase() // returns 'findMaxOfArray'
- toTitleCase()
String foo = 'hello world';
String fooTitled = foo.toTitleCase(); // returns 'Hello World'
- toSlug()
String foo = 'hello world';
String fooSlug = foo.toSlug(); // returns 'hello_world'
- toNum()
String foo = '5.5';
double fooNum = foo.toNum(); // returns 5.5
String foo2 = '5';
int fooNum2 = foo.toNum(); // returns 5
String foo3 = '5f';
var fooNum2 = foo.toNum(); // returns null
- toInt()
String foo = '5.6';
int fooInt = foo.toInt(); // returns 5
String foo2 = '5';
int fooNum2 = foo.toInt(); // returns 5
String foo3 = '5f';
var fooNum2 = foo.toInt(); // returns null
- toDouble()
String foo = '5';
double fooDouble = foo.toDouble(); // returns 5.0
String foo = '5.5';
double fooDouble = foo.toDouble(); // returns 5.5
String foo = '5f';
var fooDouble = foo.toDouble(); // returns null
- onlyLatin()
String foo = '4*%^55/es4e5523nt1is';
String letters = foo.onlyLatin() // returns 'esentis';
- onlyGreek()
String foo = '4*%^55/σοφί4e5523nt1isα';
String letters = foo.onlyLatin() // returns 'σοφία';
- onlyNumbers()
String foo = '4*%^55/es4e5523nt1is';
String onyNumbers = foo.onlyNumbers() // returns '455455231'
- readTime()
String foo = 'Hello dear friend how you doing ?';
int readTime = foo.readTime() // returns 3 seconds.
- removeNumbers()
String foo = 'es4e5523nt1is';
String noNums = foo.removeNumbers() // returns 'esentis'
String foo = '1244e*s*4e*5523n*t*1i*s'
String noNums = foo.removeNumbers() // returns 'e*s*e*n*t*i*s'
- countWords()
String foo = 'Hello dear friend how you doing ?';
int count = foo.countWords() // returns 6 words.
- capitalize()
String foo = 'hAckErrR';
String cFoo = foo.capitalize(); // returns 'Hackerrr'.
- removeLetters()
String foo = 'es4e5523nt1is';
String noLetters = foo.removeLetters() // returns '455231'
String foo = '1244e*s*4e*5523n*t*1i*s'
String noLetters = foo.removeLetters() // returns '1244**4*5523**1*'
- charOccurences()
String foo = 'esentis';
List occurences = foo.charOccurences() // returns '[{e:2},{i:1},{n:1},{s:2},]'
- mostFrequent()
String foo = 'Hello World';
String mostFrequent = foo.mostFrequent() // returns 'l'
- reverse()
String foo = 'Hello World';
String reversed = foo.reverse() ; // returns 'dlrow olleH'
- first()
String foo = 'hello world';
String firstChars = foo.first(); // returns 'h'
- last()
String foo = 'hello world';
String lastChars = foo.last(); // returns 'd'
- replaceGreek()
String foo = 'Αριστοτέλης';
String fooReplaced = foo.replaceGreek(); // returns 'aristotelis'
- findPatterns({required String pattern})
String foo = 'abracadabra';
String fooOccs = foo.findPattern(pattern:'abr'); // returns '[0, 7]'
- stripHtml()
String html = '<script>Hacky hacky.</script> <p>Here is some text. <span class="bold">This is bold. </span></p>';
String stripped = foo.stripHtml(); // returns 'Hacky hacky. Here is some text. This is bold.'
- toStringArray()
String word = 'esentis';
List<String> letters = foo.toStringArray(); // returns '[e,s,e,n,t,i,s]'
- repeat(int x)
String string = 'foo';
String stripped = foo.repeat(2); // returns 'foofoo'
- squeeze(String x)
String foo = 'foofoofoofoofoo';
String fooSqueezed = foo.squeeze('o') // 'fofofofofo';
- hasSameCharacters()
String foo1 = 'ttttttt';
bool hasSame1 = foo.hasSameCharacters() // true;
String foo = 'ttttttt12'
bool hasSame2 = foo.hasSameCharacters() // false;
- shuffle()
String foo = 'esentis';
String fooSqueezed = foo.shuffle() // 'teienss';
- getLevenshtein(String word)
String foo = 'esentis';
int distance = foo.getLevenshtein('esen') // '3';
- charCount(String char)
String foo = 'esentis';
int distance = foo.charCount('e') // '2';
- formatWithMask(String mask)
String string = 'esentisgreece';;
String mask = 'Hello ####### you are from ######';
String masked = string3.formatWithMask(mask); // returns 'Hello esentis you are from greece'