Click or drag to resize

NiceFormatterSample(String, Int32) Method

Converts a string into a nicely formatted string whre leading and trailing characters of a maximum length are displayed, but excess middle charactes are replaced with a count placeholder. It therefore displays a sample of a string of arbitrary length. The middle truncation is skipped if it is less than 8 characters long.

Namespace: Orthogonal.Common.Basic
Assembly: Orthogonal.Common.Basic (in Orthogonal.Common.Basic.dll) Version: 2024-04-15 18:00 GMT+10.f27da1471008deaf16b803c17e24a5955690aef1
Syntax
C#
public static string Sample(
	this string value,
	int sampleLength = 40
)

Parameters

value  String
The value to nicely format as a sample.
sampleLength  Int32  (Optional)
The length of the leading and trailing charcters to be shown as a sample of the string. Default is 40.

Return Value

String
A nicely formatted sample of the input string.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type String. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Exceptions
ExceptionCondition
ArgumentOutOfRangeExceptionThrown if sampleLength is less than one.
Example
C#
// String sample with 10 leading and trailing characters displayed
const string Lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
string sample = Lorem.Sample(20);
Console.WriteLine(sample);
// Produces…
// Lorem ipsum dolor si…◄16►…tur adipiscing elit.
See Also