R
Rowan
Hi,
I am somewhat new to .net and c#. (What I learned in previous co has to
be unlearned). I am doing something that seems simple but I think there
is a better way than how I learned to do it. I am creating a fixed
length file with fixed length fields. Each field either requires
leading zeros or added on spaces. I learned to create a helper class
and for every field do this:
public static string FormatFieldA(string str12)
{
if (str12 == null || str12.Trim() == "")
//Default spaces required length = 12
{
return " ";
}
else
{
Int32 l = 12 - str12.Trim().Length;
if (l != 0)
for (int i = 1; i <= l; i++)
{
str12 = str12 + " ";
}
return str12;
}
}
I think there must be a better way like specifying in the Header or
Detail class for each field the field length and whether leadingzero is
t/f and then pass each field with those values to a simple format
function. But I don't know if that is the best way and I don't know how
to assign those constants. Could someone help? I want to do this well.
I am somewhat new to .net and c#. (What I learned in previous co has to
be unlearned). I am doing something that seems simple but I think there
is a better way than how I learned to do it. I am creating a fixed
length file with fixed length fields. Each field either requires
leading zeros or added on spaces. I learned to create a helper class
and for every field do this:
public static string FormatFieldA(string str12)
{
if (str12 == null || str12.Trim() == "")
//Default spaces required length = 12
{
return " ";
}
else
{
Int32 l = 12 - str12.Trim().Length;
if (l != 0)
for (int i = 1; i <= l; i++)
{
str12 = str12 + " ";
}
return str12;
}
}
I think there must be a better way like specifying in the Header or
Detail class for each field the field length and whether leadingzero is
t/f and then pass each field with those values to a simple format
function. But I don't know if that is the best way and I don't know how
to assign those constants. Could someone help? I want to do this well.