Scroll

Custom Function: Fix length of strings

This function lets you set report values to a fixed length. Longer values are cut off, and shorter values have spaces added to match the specified length.

Arguments (Min - Max): 2 - 2

Usage

FixLength(x, y)

  • x is the string value to process
  • y is the number of characters to set the string length

Code

string text = args[0].ToString();
int length = Convert.ToInt32(args[1]);
int buffer = length - text.Length;

if (text.Length >= length)
  return text.Substring(0, length);

for (int i = 0; i < buffer; i++)
{
  // check the export type for which spacer to use
  text += (sessionInfo.Report.ExecExportType == WebReports.Api.wrExportType.Html ? "&nbsp;" : " ");
}

return text;

Hidden Article Information

Article Author
Nick
created 2016-02-01 22:44:34 UTC
updated 2017-06-20 14:47:52 UTC

Labels
functions, example, size, custom function, fixed, cut off, trim,
Have more questions? Submit a request