Description
The TruncateFilename
method is a static extension method in the SandboxSystemExtensions
class. It is used to truncate a given string to a specified maximum length, appending a specified string if truncation occurs. This is particularly useful for shortening filenames while preserving a recognizable part of the original name.
Usage
To use the TruncateFilename
method, call it on a string object, passing the maximum length and the appendage string as parameters. The method will return a new string that is truncated to the specified length, with the appendage added if truncation was necessary.
Example
// Example usage of TruncateFilename
string filename = "very_long_filename_that_needs_truncation.txt";
int maxLength = 20;
string appendage = "...";
string truncatedFilename = SandboxSystemExtensions.TruncateFilename(filename, maxLength, appendage);
// Output: "very_long_filename..."