String Extensions

NinJa provides a ton of extended functions for the base string object in JavaScript, along wrapping existing functionality with new names that follow closely the naming scheme of the .NET Framework. Here are some of the functions provided:

This is just a portion of the extra functions provided for strings. There's much more that can be find simply by studying the Intellisense in Visual Studio.

String.Format & String.BindFormat

NinJa provides a String.Format function that provides the basic functionality of String.Format in .NET where indexed tokens surrounded by curly braces, "Such as {0} <- that", and the parameters provided there after are replaced with the provided markers. To escape curly braces, simply use {{} and {}} to use { and } respectively.

String.BindFormat is slightly different. Instead of using indexed tokens, you use the names of properties to replaced the tokens with. This kind of "binding" uses the binding syntax provided by NinJa that's goes well beyond the scope of this page. Here's an example:

$Span("clock").Text(String.BindFormat("{Hours}:{Minutes}:{Seconds}", DateTime.Now());
This will display the current time. What's important to note here is that Hours, Minutes, and Seconds are not "fields" or "members" of the DateTime object, they are property functions. With BindFormat, you can provide either field/member names or function names that return values. BindFormat will take care of it all!