-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelper.cs
More file actions
27 lines (25 loc) · 708 Bytes
/
Helper.cs
File metadata and controls
27 lines (25 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System;
using System.Collections.Generic;
using System.Text;
namespace Compiler
{
class Helper
{
// Method changes a string to a constant width.
// baseString: string to change
// charLimit: max amount of characters to include
// width: constant number of chars in the result. Padding with spaces.
// return: formatted string
public static string StringFormat(string baseString, int width, int charLimit = -1)
{
if (charLimit == -1)
charLimit = width;
string result = baseString;
// limit chars
if (baseString.Length > charLimit - 3)
result = baseString.Substring(0, charLimit - 3) + "...";
// return padded string
return result.PadRight(width);
}
}
}