473,396 Members | 1,996 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,396 software developers and data experts.

Constant Column in string format

Hello Group,
My apps save to disk (as .txt file) data from Table.
I use formatting string (String.Format("{0}\t{1}\t{2}\t{3},
myTable.ItemArray). In column [1] I've different length of text.
Text is from 1 to 15 chars.

How set in text file constant width for columns.
Thx PawelR

Nov 15 '05 #1
2 7560
You want column 2, 3 and 4 to be neatly aligned in the text file?

Well, you could add blank spaces to the string in column 0 to make it 15
characters long.

String blank = " ";
String firstValue = (string)myRow[0];
firstValue += blank.SubString(0, 15 - firstValue.Length);

String finalString = String.Format("{0}\t{1}\t{2}\t{3}", firstValue,
myRow[1], myRow[2], myRow[3]);

Note, I haven't tested this code, and especially the String.Format may not
work.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #2
Hi Paweł,
Hello Group,
My apps save to disk (as .txt file) data from Table.
I use formatting string (String.Format("{0}\t{1}\t{2}\t{3},
myTable.ItemArray). In column [1] I've different length of text.
Text is from 1 to 15 chars.

How set in text file constant width for columns.
Thx PawelR


Use the simple formatting:

string stringItem=myTable.Rows[0].ItemArray[1];
String.Format("{0,-15}"
, stringItem);

//or

String.Format("{0,15}"
, stringItem);

Greetings/Pozdrowienia

Marcin
Nov 15 '05 #3

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

Similar topics

1
by: pcb | last post by:
Hi all, Perhaps a silly question. I've been trying to format the list items in a listbox by appending a constant text string to the values. Here is the code: ******** 'Build SQL string...
0
by: PawelR | last post by:
Hello Group, My apps save to disk (as .txt file) data from Table. I use formatting string (String.Format("{0}\t{1}\t{2}\t{3}, myTable.ItemArray). In column I've different length of text. Text is...
2
by: Uri Dor | last post by:
Hi, everyone, The question is whether there is (or can be) an FxCop rule that makes sure I don't do this: String.Format("{0}-{1}-{2}", 5); Or similar things. Some explanations: 1) of course I...
0
by: PawelR | last post by:
Hello Group, My apps save to disk (as .txt file) data from Table. I use formatting string (String.Format("{0}\t{1}\t{2}\t{3}, myTable.ItemArray). In column I've different length of text. Text is...
8
by: **Developer** | last post by:
ControlRichTextBox1.SelectedText = String.Format("{0} {1}", strExt, x.szTypeName) & vbCrLf Three questions: 1) How can I insert a tab between {0} and (1} so the richtextbox tabs...
1
by: Agnes | last post by:
dim strPeriod as string = dtTransdate.ToString("dd-MMM-yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo) '--excel code ..Range("H2").Value = strPeriod When I read the excel, the...
4
by: MC | last post by:
In C, printf allows us to specify a runtime (non-constant) field width of a formatted value by using the * character. Is there something like that for System.String.Format? In C#, I find myself...
2
by: tstephan | last post by:
In the docs for String.Format there is an alignment component which allows you to pad the field to a certain number of spaces. e.g. FormatFName = String.Format("First Name = |{0,10}|", myFName);...
0
by: santoshsri | last post by:
Please have a look at below code snippet - in the first snippet I have made constant to provide a static format to string.. the second uses the constant to string.format the values received at...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.