using System;
using System.IO;
class Program
{
static void Main()
{
string inputFilePath = "input.txt"; // Path to the input file
string outputFilePath = "output.txt"; // Path to the output file
// Define column lengths
int[] columnLengths = { 1, 21, 51, 81, 131, 141 };
// Read all lines from the input file
string[] lines = File.ReadAllLines(inputFilePath);
// Create an array to hold the formatted lines
string[] formattedLines = new string[lines.Length];
// Process each line
for (int i = 0; i < lines.Length; i++)
{
string line = lines[i];
string formattedLine = "";
// Split the line into columns based on the column lengths
int currentIndex = 0;
foreach (int length in columnLengths)
{
if (currentIndex < line.Length)
{
int lengthToUse = Math.Min(length, line.Length - currentIndex);
string column = line.Substring(currentIndex, lengthToUse).Trim();
formattedLine += column.PadRight(length) + " ";
currentIndex += lengthToUse;
}
}
// Add the formatted line to the array
formattedLines[i] = formattedLine;
}
// Write the formatted lines to the output file
File.WriteAllLines(outputFilePath, formattedLines);
Console.WriteLine("File formatted successfully.");
}
}
Dear
Try this,