String prototype extensions
Extends string prototype with the following methods: camelize, capitalize, collapseSpaces, format, ltrim, pad, remove, repeat, reverse, rtrim, sprintf, stripTags, trim, truncate
This extensions doesn't depend on any other code or overwrite existing methods.
- camelize() : StringConverts a string separated by dashes and/or underscores into a camelCase equivalent. For instance, 'java-script' would be converted to 'javaScript'.
Example:
"java-script".camelize();
Result:
"javaScript"
Example:
"java_script_methods".camelize();
Result:
"javaScriptMethods"
Example:
"java_script-methods".camelize();
Result:
"javaScriptMethods"
- capitalize() : StringCapitalizes the first letter of a string and downcases all the others.
Example:
"my name is harry".capitalize();
Result:
"My Name Is Harry"
- collapseSpaces() : StringEntfernt Whitespace am Anfang und Ende des Strings und reduziert Whitespace innerhalb des Strings auf ein Zeichen.
Example:
" My name is Harry! ".collapseSpaces();
Result:
"My name is Harry!"
- format(Array<String> substrings) : StringSubstitute substrings from an array into a format String that includes '%1'-type specifiers
Example:
"My %0 is %1".format(['name','Harry']);
Result:
"My name is Harry"
- ltrim() : StringRemoves leading whitespace.
Example:
" My name is Harry!".ltrim();
Result:
"My name is Harry!"
- pad(Int length, String ch, Int direction) : StringPad a string up to a given length. Padding characters are added to the left of the string.
Example:
"22".pad(4, '#');
Result:
"##22"
Example:
"22".pad(4, '#', 1);
Result:
"22##"
- remove(Int start, Int length) : StringRemoves a specified length of characters from a given postion.
Example:
"JavaScript".remove(4, 6);
Result:
"Java"
- repeat(Int count, String separator) : StringReturns 'str' repeated 'count' times, optionally placing 'separator' between each repetition
Example:
"Hello".repeat(5);
Result:
"HelloHelloHelloHelloHello"
Example:
"Hello".repeat(5,'#');
Result:
"Hello#Hello#Hello#Hello#Hello"
- reverse() : StringReverses the characters in the specified string.
Example:
"Hello".reverse();
Result:
"olleH"
- rtrim() : StringRemoves trailing whitespace.
Example:
"My name is Harry! ".rtrim();
Result:
"My name is Harry!"
- stripTags() : StringReturns a string with all HTML tags stripped.
Example:
"<div id='type'>JavaScript</div>".stripTags();
Result:
"JavaScript"
- trim() : StringReturns a String with with leading and trailing whitespace removed.
Example:
" My name is Harry! ".trim();
Result:
"My name is Harry!"
- truncate(Number length, String suffix) : StringReturns a string that is no longer than a certain length.
Example:
"JavaScript ".truncate(5);
Result:
"Ja..."
Example:
"JavaScript ".truncate(5, "#");
Result:
"Java#"