AdvantageCMS.Core.Common.BaseClasses Namespace
Advantage CSP

StringExtensions..::..Shorten Method (String, Int32, Boolean)

Gets a Shortened version of a string

Namespace:  AdvantageCMS.Core.Common
Assembly:  AdvantageCMS.Core (in AdvantageCMS.Core.dll)

Syntax


public static string Shorten(
	this string text,
	int length,
	bool truncateWords
)

Parameters

text
Type: String
The text.
length
Type: Int32
The length.
truncateWords
Type: Boolean
if set to true [truncate words].

Return Value

return string of shortened text

Remarks


if we want to trucate words if text needs shortening, shorten the text at the exact length given if the text does not need shortening, return the text as is if we do not want to trucate any words split text into an array of words loop through all words if the new return value will be longer than the allowed value don't append anymore words append the new word to the return value and a space get trimmed version of return value if the values length is les than the allowed length return original value if the values length is not less than the allowed length return shortened value