String Template Class in C#

CsharpProgrammingServer Side Programming

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 });
raja
Published on 21-Aug-2018 07:49:02

Advertisements