Thursday, July 2, 2009

Create fixed size string for CSV file in C#

public static string GetFixedLengthString(string input, int length)
{
string result = string.Empty;
if (string.IsNullOrEmpty(input))
{
result = new string(' ', length);
}
else if (input.Length > length)
{
result = input.Substring(0, length);
}
else
{
result = input.PadRight(length);
}
return result;
}

No comments:

Post a Comment