String stuffing with characters

S

Shikari Shambu

I need to create a pipe separated flat file where if the field lengths of
data elements are fixed and if data is less than the field length or does
not exist there are dummy characters stuffed. Is there a way to do this
efficiently ( a stuff function or something similar).

Say, I have three fields A (5), B(5) and c(5) and if there is data only for
A (one), B(two) the line in the file should read
one~~|two~~|~~~~~

where tilde is the stuff character and | is the field separator.

TIA
 
A

Alberto Poblacion

Shikari Shambu said:
I need to create a pipe separated flat file where if the field lengths of
data elements are fixed and if data is less than the field length or does
not exist there are dummy characters stuffed. Is there a way to do this
efficiently ( a stuff function or something similar).

Yes, the String.PadRight method does what you want.

Say, I have three fields A (5), B(5) and c(5) and if there is data only
for A (one), B(two) the line in the file should read
one~~|two~~|~~~~~

string[] fields = {"one", "two", ""};
foreach (string f in fields)
{
fields = fields.PadRight(5, '~');
}
result = string.Join("|", fields);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top