This very simple extension method makes a string a fixed length. It appends whitespace to a string that is shorter than required or strips characters to a string to is longer than requested.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ParaPlan.Extensions
{
public static class StringHelper
{
public static string ToFixedLength(this string s, int width)
{
string rv = s;
if (s.Length > width)
{
rv = s.Remove(width);
}
else
{
int neededWhiteSpace = width - s.Length;
rv = s + new string(char.Parse(" "), neededWhiteSpace);
}
return rv;
}
}
}