Table of Contents
String.Extras
MooTools extends Strings in its Native group of code. We've got a few more extensions of our own.
stripTags
Removes all html tags from a string:
"<p>I\'m a <b>string</b> with a bunch of <i>tags</i></p>".stripTags(); //returns: I'm a string with a bunch of tags

cleanQueryString
Removes from a query string any keys that have empty values.
var cleaned = "a=b&x=&z=123&e=".cleanQueryString(); //cleaned = "a=b&z=123"

You can pass in a custom function to use instead of the default:
var noNumberValues = "a=b&x=y&z=123&e=".cleanQueryString(function(set){ //set is "a=b", "x=y", "z=123", "e=" return !set.split("=")[1].match(/[0-9]/); }); //noNumberValues = "a=b&x=y&e="

findAllEmails
Finds all the valid email addresses in a string.
"Fred's email is fred@flintstone.com and Barney's is barney@rubble.com".findAllEmails(); //returns ['fred@flintstone.com', 'barney@rubble.com']

parseQuery
This takes a url query string and returns an object of name/value pairs to you.
"apple=red&lemon=yellow".parseQuery(); //returns: {apple: 'red', lemon:'yellow'}

tidy
Removes MS-Word style non-ASCI characters (curly quotes, elipse, etc). See also Element.tidy.
"“‘…’”".tidy(); //returns "'...'"

cnet-libraries/03-native/03-string.extras.txt · Last modified: 2008/11/18 00:07 by aaron-n