views:

17

answers:

1

I have a large data.DataTable and some formatting rules to apply. I'm sure this is not a unique problem.

For example, the LASTNAME column has a value of "Jones" but my formatting rule requires it be 10 characters padded with spaces on the right and uppercase only. Like: "JONES "

My initial thought is to loop through each row and generate a string. But, I wonder if I could accomplish this more efficiently with a DataView, LINQ or something else.

Can someone point me in a direction?

+2  A: 

It really depends how you display the results. I would say if you display it in a grid, the easiest would be to do a quick loop, no real performance harm there in a datatable.

If you display the records individually you can create an extension method for your string, and simply call it like this for example. LastName.Padded()

public static class StringExtensions
{
   public static string Padded(this string s)
   {
       return s.ToUpper().PadRight(10);
   }
}
Ryk
Thank you. That seems straight-forward and reasonable. I guess I mostly wanted to make sure there was something I was overlooking.
Rob P.