String Template Class in C#


StringTemplate class is used to parse the format string, so that it is compatible with String.Format. The StringTemplate class comes under the NString library that has extension methods. These methods makes string manipulations easy to use like.

IsNullOrEmpty()
IsNullOrWhiteSpace()
Join()
Truncate()
Left()
Right()
Capitalize()

StringTemplate.Format is better than String.Format since it is more readable and less prone to errors.

The order of the values can be easily formatted. The values are formatted in a way similar to String.Format, but with named placeholders instead of numbered placeholders.

The following is a sample −

string str = StringTemplate.Format("{ExamName} will held on {ExamDate:D}", new { p.ExamName, p.ExamDate });

Updated on: 22-Jun-2020

331 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements