- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHPPhysics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
String Formatting in C# to add padding on the right
To add padding on the right to a string −
const string format = "{0,10}";
Now add it to the string −
string str1 = string.Format(format, "Marks","Subject");
Let us see the complete code −
Example
using System;
public class Program {
public static void Main() {
// set right padding
const string format = "{0,10}";
string str1 = string.Format(format, "Marks","Subject");
string str2 = string.Format(format, "95","Maths");
Console.WriteLine(str1);
Console.WriteLine(str2);
}
}
Output
Marks 95
Advertisements