Skip to content
StevePotter edited this page Apr 21, 2011 · 8 revisions

Yo welcome to wetnap. Wetnap is a simple drop-in dll that has a bunch of useful extension methods. It just makes programming with .net a bit better. These little helpers have become a big part of my programming and I want to share them with the world.

Cool String Extensions

Wetnap provides lots of helpful string extensions. Over the years, I noticed myself doing some stuff over and over. For example, I kept writing code that ensures a string starts with a certain value. Normally that requires a few lines, but wetnap makes it easy:

"google.com".startWith("http://"); //"http://google.com"
"http://google.com".startWith("http://"); //doesn't change anything cuz it already starts with it

Or this one:

"www.google.com".Before("google");  //"www."

Don't you hate string.IsNullOrEmpty? Me too. Now you can just use the HasNoChars extension method:

string str = null; str.HasNoChars();  //true
"hi".HasNoChars();  //false
"hi".HasNoChars();  //false

Or instead of

if ( !string.IsNullOrEmpty(foo) )

you just write

if ( foo.HasChars() )

Nice, right?

string toFormat = "{FirstName} says hi";
toFormat.Format(new { FirstName = "Jen"});   //yields "Jen says hi"

Or this gem:

"I'm a long annoying string whose length you don't know".Truncate(12,StringTruncating.EllipsisWord) //"I'm a long..."
Clone this wiki locally