String.PadLeft is a method in C#, which returns a new string of a specified length in which the beginning of the current string is padded with spaces or with a specified Unicode character.
Questions tagged [padleft]
23 questions
12
votes
1 answer
Convert int to string with leading zeros
I have an integer which I want to convert to a string with leading zeros.
So I have 1 and want to turn it into 01. 14 should turn into 14 not 014.
I tried:
let str = (string 1).PadLeft(2, '0') // visual studio suggested this one
let str = (string…

Snæbjørn
- 10,322
- 14
- 65
- 124
3
votes
2 answers
Trying to pad decimal number with leading spaces
for (int iCount = 0; iCount < oForm.LineItems.Count; iCount++)
{
// cartDetails is a stringbuilder here.
cartDetails.Append(String.Format("{0:0}", oForm.LineItems[iCount].Quantity));
cartDetails.Append(String.Format("{0:0.00}",…

NewCoder
- 99
- 4
- 13
2
votes
1 answer
Where is the source code from 'private extern String PadHelper'
When I was looking for the following source code in .NET source code, I didn't find source for PadHelper that is the method inside PadLeft and PadRight.
Is there something wrong with my search?
[System.Security.SecuritySafeCritical] //…

Juan Ruiz de Castilla
- 964
- 14
- 25
2
votes
1 answer
How to use padleft for negative integers?
I need to add leading zeros to numbers which may be negative or positive. I am able to add them fine for positive numbers. How do I do the same for negative numbers?
For example:
int number1 = 1;
string pad1 = number1.ToString().PadLeft(3,…

Procrastinating Programmer
- 294
- 1
- 5
- 21
1
vote
0 answers
WPF RichTextBox Messenger chat style alignment
im using a WPF RichTextbox to display messages from other people and myself. The issue is not when receiving messages. since the allignment is perfect for left alligned text as traditionally done in messanging apps. The issue is when trying to…
1
vote
2 answers
Aligning text into three columns
I would like to show the LinkedList data into three separate columns with List1, List2, and List3 as the column heading. I am unable to align the LinkedList data under these headings.
void LoopThruLinkedList(LinkedList strList)
…

LearningCSharp
- 57
- 5
1
vote
2 answers
Padleft string using '0'
I have this chunk of code
long num = Int64.Parse(Convert.ToString(random.Next(0, 65535), 2).PadLeft(16, '0'))
When using this code the string is not padded with the leading zeros. I'm not sure, but my guess is maybe when the string is parsed it…

Timmy
- 543
- 1
- 7
- 19
1
vote
1 answer
Cannot use PadLeft() in lambda expression
I can use PadLeft() method in Razor View as shown below without any problems:
@Model.Project.PKey - @Model.IssueNum.ToString().PadLeft(5, '0')
However, I cannot create the same statement in the controller using the same viewmodel:
var result =…

Jack
- 1
- 21
- 118
- 236
1
vote
2 answers
Copy-Item and PadLeft
I need to retrieve pdf file and copy this pdf file from source to destination. The pdf name are in txt file listspec one number by line :
100
200
204
79002
XS002
I concatenate the .pdf extension
But the pdf files are 00100.pdf, 00200.pdf,…

user3914656
- 23
- 3
0
votes
1 answer
Can you please explain how padleft works in C#
Can you please explain me this code -
return string.Join(string.Empty, checkSum.Select(x => Convert.ToString(x, 2).PadLeft(8, '0')).
checkSum will have binary value like 10101010100011.
Checked in google but didn't find clear explanation.

Syed
- 1
- 1
0
votes
1 answer
Windows PowerShell, PadLeft
i need to make files name string like text_000.txt, where 000 should increase every file but i got problem like this where after 10 iterations the digits in the file name become more than necessary
i need to get file name like "text_001.mp3"
and…

depress.
- 3
- 2
0
votes
1 answer
SQL Remove all leading zeros
My join returns null because I am not able to remove the leading zeros. Basically, I am trying to replace the pol.Policy_Number with src.Policy_Number for a large number of policies. Is there a way I can remove the leading 0s in the ON statement for…

Heike
- 149
- 1
- 1
- 11
0
votes
1 answer
Why is no padLeft function in my flutter?
My dart is Dart SDK version: 2.10.4 (stable) (Wed Nov 11 13:35:58 2020 +0100) on "windows_x64", but I can't use padLeft(), does anyone tell me why? what can I do next?

mikezang
- 2,291
- 7
- 32
- 56
0
votes
1 answer
Padleft not adding zeros in strings when the length is under the length of the padleft?
So I wanted to make a random timestamp generator in c# which had to be a string.
I came up with a random generator made out of loads of random.next's
but when the day month hour or minute is under 10 it has to have a zero in front, or the string…

Swift
- 21
- 8
0
votes
2 answers
How do I pass a String into a function in an NVelocity Template?
I'm using the NVelocity Templating engine to produce a fixed-length field output - you know the kind of thing:
Field Start Pos Field Length Notes
---------- --------- ------------ ---------
Supplier 1 7 …

Andrew
- 12,991
- 15
- 55
- 85