---
title: "Spacing in String.Format()"  
description: "Spacing in String.Format()"  
author: "Jayden Bell"  
published: 2013-09-23  
updated: 2013-09-23  
canonical: https://www.mindstick.com/forum/1492/spacing-in-string-format  
category: "wpf"  
tags: ["String.Format()", "wpf", "mindstick", "Spacing in String.Format()"]  
reading_time: 1 minute  

---

# Spacing in String.Format()

I want fixed spacing between words in a string similar to what you have in a datagrid.

I tried:

string [item](https://www.mindstick.com/forum/156564/remove-item-in-an-array-in-javascript) = [String.Format](https://www.mindstick.com/forum/1763/string-format-with-null-values-c-sharp)("{0,-9}{1,-42}{2,-24}{3,0}", ++i, itemName, itemQuantity, totalItemPrice.ToString("#,##0.00") + System.Environment.NewLine);

But since the itemName [length](https://www.mindstick.com/interview/1915/what-is-the-difference-between-char_length-and-length) is varaible itemQuantity and totalItemPrice do not maintain their positions and get pushed forward.

\

The string is subsequently assigned to a RichTextBox.

## Replies

### Reply by Sumit Kesarwani

Hi Jayden,

You can do like this:

I have just modified the way you have used the values and I can get the data displayed as data grid.

[string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) itemName = "phone";

int itemQuantity = 5, totalItemPrice=50;

string item = String.Format("{0,-2}{1,-10}{2,-5}{3,-5}", ++i, itemName, itemQuant ity, totalItemPrice.ToString("#,##0.00")+System.Environment.NewLine);


---

Original Source: https://www.mindstick.com/forum/1492/spacing-in-string-format

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
