default image
default image
in ,

Truncate my strings with a “…” if they are too long?

Here is the logic wrapped up in an extension method:

public static string Truncate(string value, int maxChars)
{
    return value.Length <= maxChars ? value : value.Substring(0, maxChars) + "...";
}
Usage:

var s = "abcdefg";

Console.WriteLine(s.Truncate(3));
 

Author Profile

PREM KUMAR
PREM KUMAR
Hey Its..! Tech Lover , Ionic, Angular, Typescript, Dotnet Core, Node, Like Opencv, AI, ML, Robotics, Iot, Love Music, Cooking, Girls, Innovation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

What do you think?

400 Points
Upvote Downvote
Cut your low priority activities

Godaddy Security Exception Error Removal

ionic tutorial

Getting up and running with IONIC 2..