Skip to content

Instantly share code, notes, and snippets.

@dkarzon
dkarzon / StringExtensions.cs
Created April 13, 2011 04:36 — forked from lukencode/StringExtensions.cs
String Extensions
public static class StringExtensions
{
/// Like linq take - takes the first x characters
public static string Take(this string theString, int count, bool ellipsis = false)
{
int lengthToTake = Math.Min(count, theString.Length);
var cutDownString = theString.Substring(0, lengthToTake);
if (ellipsis && lengthToTake < theString.Length)
cutDownString += "...";