473,785 Members | 2,819 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Padding strings (System.Console .Write)

2 New Member
Hey all, a beginner at C# here.

I'm writing a console application in C# where i handle a lot of numerical data, and try to present them in a coherent, nicely aligned form.

I'm using System.Console. WriteLine

I have 8 - 10 columns of data for each record, each item per record contains 1 to 10 digits.

The problem i have is that i can't figure out how to align things. '\t' obviously wouldn't work well, because if you're on a tab boundary, it will screw things up.

I figured out that i could use the format specifier {0:d10} but that pads zeroes in front of each number, this is close to what i want

is there a way to do blank space padding instead of zero padding like with {0:d10}?

thanks for any help
Oct 6 '09 #1
4 3940
GaryTexmo
1,501 Recognized Expert Top Contributor
http://msdn.microsoft.com/en-us/library/92h5dc07.aspx

Try that? You can pad the string with spaces based on the length of the string.
Oct 6 '09 #2
Grumblegut
2 New Member
so i have to...


myvar.ToString( ).PadRight(10,' ') for each and every entry?

allright, i was hoping there was a nice format specifier, but i guess i have to bite the bullet.
Oct 6 '09 #3
GaryTexmo
1,501 Recognized Expert Top Contributor
Oh, there might be, I just don't know of it :D

I did a google, is this what you're looking for?
http://blog.stevex.net/string-formatting-in-csharp/

... I'm not sure that it is.
Oct 7 '09 #4
Plater
7,872 Recognized Expert Expert
You want them RIGHT padded? Odd.
Left padding is very easy to do:
Expand|Select|Wrap|Line Numbers
  1. int dd = 4531;
  2. string s=string.Format("{0,10}",dd);
  3.  
Oct 7 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

14
11096
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a window.open function? I would prefer not to create a separate HTML page. So far all I have is the basic var cwin = window.open('images/KJV-THANKS.gif', 'Thanks', 'width=243,height=420,'); cwin.focus();
10
5284
by: Eranga | last post by:
I have the following code; string test1 = words;//"Exclud" string test2 ="Exclud"; string test3 = String.Copy(words);//"Exclud" bool booTest1 = test1.Equals(test2);//false bool booTest2 = test2.Equals("Exclud");//true bool booTest3 = test1.Equals("Exclud");//false bool booTest4 = words.Equals("Exclud");//false bool booTest5 = test3.Equals("Exclud");//false
1
6611
by: Nicholas Holder | last post by:
A client creates a connection to the server using the TCPListener/Client classes and transfers data via a NetworkStream. When the client connects, the server creates a process and redirects its StandardOut to traverse back over the network to the client. I want to encrypt this data and the code I have is below. However, occasionally during processing, I receive an exception stating the PKCS7 padding is invalid and cannot be removed. I have...
73
2957
by: Rigga | last post by:
Hi all, I am wondering why string's are not true objects?.... Let me explain... If i write the code Dim x1 as String = "veg" Dim x2 as String = "veg" If x1 = x2 then
20
1487
by: djc | last post by:
I get this *intermittently* on a utility I am working on. I don't know whats going on but here are a few points about it: - using VS 2005, running on xp sp2 - program uses multiple threadpool threads - only happens when built with the 'release' configuration (no debug flag, compiler optimizations in effect) - no problems in debug config here is the error: Unhandled Exception: System.AccessViolationException: Attempted to read or write...
5
10532
by: Tom | last post by:
I am having a problem where an extra gap (whitespace, padding) appears in a table cell where I don't want it. The data fed in the table is via dynamic HTML, so the amount in the middle cell may vary. When the data in the middle table cell is little and that cell's height is small, an unwanted gap appears in the first table cell. I would prefer to have all additional blank space at the bottom of the table (last row) and not have any in...
3
5834
by: floppyzedolfin | last post by:
Hi there. I'm coding an encryption / decryption program. At this very moment, I think I should be pretty close from the end, but there's something blocking me on my way. There's a "Padding is invalid and cannot be removed" error raised when closing the cryptostream (or FlushFinalBlock-ing it). For what I have read, Padding errors are due to an incorrect padding : PKCS7 is recommended.
4
7670
by: Dylan Nicholson | last post by:
I can write a regular expression that will only match strings that are NOT the word apple: ^(.*|a.*|ap.*|app.*|apple.+)$ But is there a neater way, and how would I do it to match strings that are NOT the word apple OR banana? Then what would be needed to match only strings that do not CONTAIN the word "apple" or "banana" or "cherry"?
0
10324
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10090
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.