Hi All,
I would like to generate a random Fixed Width Files as below.Example:
I have a file something as below:
NAME STATE TELEPHONE
SDFFF WA 418-Y11-4111
DFFFF CA 319-Z19-4341
fjffhjh IL 219-532-c301
- First column is 20 characters. It is left aligned. It is padded with spaces. It contains the NAME data within it.
- Second column is 10 characters. It is left aligned. It is padded with spaces. It contains the STATE data within it.
- Third column is 12 characters. It is left aligned. It is padded with spaces. It contains the TELEPHONE data within it.
Do we have any tutorials or lbrary to acheive. I appreciate your help.
Thanks,
Karthick

Pankajkumar PatelRank #181 · 13.4K reputationPosted Sep 29, 2021, 12:17 PM EDT
Hi Karthick Subramanian,
You can Generate Fixed Width Files using PadRight as following:
string[,] data = new string[4, 3] {{"NAME","STATE","TELEPHONE"}, {"SDFFF","WA","418-Y11-4111"}, {"DFFFF","CA","319-Z19-4341"}, {"fjffhjh","IL","219-532-c301"} }; for (int i = 0; i < 4; i++) { Console.WriteLine("{0}{1}{2}", data[i, 0].PadRight(20), data[i, 1].PadRight(10), data[i, 2].PadRight(12)); }Here, for simplicity:
Hope, this will help you!