Home >Backend Development >C#.Net Tutorial >String template class in C#

String template class in C#

PHPz
PHPzforward
2023-08-24 15:13:021168browse

String template class in C#

The StringTemplate class is used to parse the format string to make it compatible with String.Format. StringTemplate class belongs to NString library, which has extension methods. These methods make string manipulation easy to use, e.g.

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

StringTemplate.Format is better than String.Format because it is more readable and less error-prone.

The order of values ​​can be easily formatted. The values ​​are formatted similarly to String.Format, but using named placeholders instead of numbered placeholders.

The following is an example −

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

The above is the detailed content of String template class in C#. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete