Aligning Text that is output to file? Columns
String.Format is your friend here.
It's very powerfull and gives you the function to align your output.
For example: (EDIT: removed the txt prefix because could be confusing, now I suppose that data to be formatted is contained in string vars)
Dim result as string
result = String.Format("{0,-10}{1,-30}{2,-30}{3,-10}{4,20}", Record, Name, Address, Telephone, Something)
The result will be aligned to the left in a 10 space column for the first element (txtRecord) and so on for the remainders, the last element will be formatted in a column with 20 space and right aligned
If that's not enough look at composite formatting to get other useful options
JonE
A Software engineer based in London. I work with ReactJS and a C# backend on a daily basis, and enjoy tackling all sorts of problems. I am super passionate about code, best practice and learning all the cool stuff surrounding software development. Here are some projects I have done: BinanceDotNet - The Official dotnet API wrapper for the Binance Cryptocurrency exchange Halo-API - C# Wrapper for the Official Halo Franchise API Redux Synapse - Alternative to react-redux that provides an observer based HoC subscriber system for your react components Or check me out on medium where I talk about projects, media, software and games
Updated on June 05, 2022Comments
-
JonE almost 2 years
I have some data which I run through, which generates a textfile.
The data is all pulled correctly, but it doesn't format correctly.
Right now, I am using TAB + Variable to space between each column but it is obviously made uneven as different variables differ in character length. Here is the layout:
RECORD NAME ADDRESS TELEPHONE SOMETHING SOMETHING ... Data is here.
Any ideas?