You could use a simple C# extension method (or directly on your Contact model):
public static class YourContactModelExtensions {
public static string ToStringMyCustomFormat(this YourContactModel m) {
// TODO
}
}
or if you wanted it to apply to all strings:
public static class StringExtensions {
public static string ToMyCustomFormat(this string s) {
// TODO
}
}
or a Razor helper function on your Razor page:
@helper ToStringMyCustomFormat(YourContactModel m) {
@* TODO *@
}
or
@helper ToMyCustomFormat(string s) {
@* TODO *@
}