473,386 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Formating output text

Hi!

I need to write some strings in text file, it consist 3 columns and it
must looks like:

ID Name Points
======================
1 Mike 4,5
2 Joseph 1,2
3 Freddy 12,3

The data is in listview control and i know how to get it from it
but when when I put this records in file i can't make to format
these record. I try to use .PadLeft and .PadRight but all i get is
something like this:

ID Name Points
======================
1 Mike 4,5
2 Joseph 1,2
3 Freddy 12,3

How to make that all columns are alligned?
Apr 3 '08 #1
4 1814
On Apr 3, 3:53*pm, Joza <josip.pejako...@MAKNIOVOetfos.hrwrote:
Hi!

I need to write some strings in text file, it consist 3 columns and it
must looks like:

ID * * *Name * *Points
======================
1 * * * Mike * * * 4,5
2 * * * Joseph * * 1,2
3 * * * Freddy * *12,3

The data is in listview control and i know how to get it from it
but when when I put this records in file i can't make to format
these record. I try to use .PadLeft and .PadRight but all i get is
something like this:

ID * * *Name * *Points
======================
1 * * * Mike * * * 4,5
2 * * * Joseph * * *1,2
3 * * * Freddy * * *12,3

How to make that all columns are alligned?
There are not alligned in the "corrected" example to begin with.
In any case you will have to do it manually, I know of no provider
that does this formatting (fixed length fields).
It's very easy in fact, all you have to do is pritn the field value,
and pad it with white spaces ( [size of the field] - [size of the
actual value] ). Of course you have to check for overflow.
Apr 3 '08 #2
Ignacio Machin ( .NET/ C# MVP ) wrote:
>
There are not alligned in the "corrected" example to begin with.
In any case you will have to do it manually, I know of no provider
that does this formatting (fixed length fields).
It's very easy in fact, all you have to do is pritn the field value,
and pad it with white spaces ( [size of the field] - [size of the
actual value] ). Of course you have to check for overflow.
I try like this:

string var="";
string txt1 = "ABCD";
string txt2 = "EFGHIJK";
string num1 = "2.4";
string num2 = "6.5";
int myFieldSize = 35;

Console.WriteLine(txt1 + var.PadRight(myFieldSize - num1.Length) + num1);
Console.WriteLine(txt2 + var.PadRight(myFieldSize - num2.Length) + num2);

And the result is something like:

ABCD 2.4
EFGHIJK 6.5

instead of

ABCD 2.4
EFGHIJK 6.5

I just don't get it... :(
Apr 3 '08 #3
Ignacio Machin ( .NET/ C# MVP ) wrote:
>
There are not alligned in the "corrected" example to begin with.
In any case you will have to do it manually, I know of no provider
that does this formatting (fixed length fields).
It's very easy in fact, all you have to do is pritn the field value,
and pad it with white spaces ( [size of the field] - [size of the
actual value] ). Of course you have to check for overflow.
I try like this:

string var="";
string txt1 = "ABCD";
string txt2 = "EFGHIJK";
string num1 = "2.4";
string num2 = "6.5";
int myFieldSize = 35;

Console.WriteLine(txt1 + var.PadRight(myFieldSize - num1.Length) + num1);
Console.WriteLine(txt2 + var.PadRight(myFieldSize - num2.Length) + num2);

And the result is something like:

ABCD 2.4
EFGHIJK 6.5

instead of

ABCD 2.4
EFGHIJK 6.5

I just don't get it... :(
Apr 3 '08 #4

"Joza" <jo*************@MAKNIOVOetfos.hrwrote in message
news:ft**********@garrison.globalnet.hr...
Ignacio Machin ( .NET/ C# MVP ) wrote:
>>
There are not alligned in the "corrected" example to begin with.
In any case you will have to do it manually, I know of no provider
that does this formatting (fixed length fields).
It's very easy in fact, all you have to do is pritn the field value,
and pad it with white spaces ( [size of the field] - [size of the
actual value] ). Of course you have to check for overflow.

I try like this:

string var="";
string txt1 = "ABCD";
string txt2 = "EFGHIJK";
string num1 = "2.4";
string num2 = "6.5";
int myFieldSize = 35;

Console.WriteLine(txt1 + var.PadRight(myFieldSize - num1.Length) + num1);
Console.WriteLine(txt2 + var.PadRight(myFieldSize - num2.Length) + num2);
You need to use the first column when calculating how much padding to add,
i.e.:
Console.WriteLine(txt1 + var.PadRight(myFieldSize - txt1.Length) + num1);
Console.WriteLine(txt2 + var.PadRight(myFieldSize - txt2.Length) + num2);

Also note that this will only align correctly if you view it using a
fixed-width font

/claes

Apr 4 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Polar | last post by:
I have a database that stories entries of short stories for a writers website. I can easily input the data into MYSQL but my trouble lies in retrieving the data. the story in just cut and...
1
by: gevayl | last post by:
Hi, Is it possible to do memo text formating in ms access 2000? I mean like underlining a portion of text in a memo field or a text field? Thank you.
3
by: comp_novice | last post by:
I need to control the number of digits to be printed after the exponential. Please have a look at the example below: float fVal = 0.06854344 The printf that I am using is fprintf(pfile,...
4
by: djc | last post by:
Is there a property or method of the textbox web server control that I can use to format the text in it a certian way. For example I am displaying a date value from a database in a text box. It...
0
by: fragmonster | last post by:
Hi, I need to manipulate XML files with PHP. So i need to extract and insert nodes in my files. For the extraction : no problem with XPath, it works fine. But, for inserting new nodes, it's...
3
by: pv1 | last post by:
Hello, I am somewhat new to Access and vba, but am trying to complete a request that has been made of me. Access version 2002 WindowsXP. At this point these text boxes are bound to the table...
10
by: olivier.scalbert | last post by:
Hello, the following constraints: source: <Source> <Item>AAA</Item> <Item>BBBBBBBBBBB</Item> <Item>CCCCCCCCC</Item> <Item>DDDDDDDDDDDDDDD</Item>
2
by: sitko | last post by:
Hi, I'm in the process of converting a VB.net program into a C program so it can run on a unix like machine. I've been moving along at a nice pace, but this conversion has stumped me. I need...
3
by: Soulspike | last post by:
Hello all I have a little formating problem. I have a query with the following code for one of the fields IIf(DatePart("ww",!,2,2)=53,"1", (DatePart("ww",!,2,2))) This code should...
15
by: jbradly | last post by:
I have a form with only one element (a text area created in Dreamweaver.) I want a user to input text in the form in any way he wants(such as paragraphs) and have it output pretty much the same way...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.