0

I am reading incoming text streams in my C# app, when I look at each string in the debugger and copy and paste its contents into Notepad++ I see that there is clear formatting like so:

SEMI MILK                    1      1.19
PERSIL WUL                   1      1.00
BUR JAM DODG                 1      1.25

But when I add each string to a List and display on screen like so I see that the formatting is off:

enter image description here

How can I get the text to diaplay exactly the same as it displays in Notepad++

The display is made up as follows:

1. DataGrid _dataGrid;
2. _dataGrid.ItemsSource = TextContent;
3. TextContent = new ObservableCollection<Textline>();
4. TextContent is simply a class with a string Property to store any text for display.
4
  • 1
    How are you displaying it on screen? Can't you use a grid view of some kind? You haven't specified if this is WinForms/WPF/Console/Other.
    – Equalsk
    Commented Nov 3, 2016 at 16:48
  • I updated my question
    – Harry Boy
    Commented Nov 3, 2016 at 16:55
  • If you're sticking it into a datagrid surely you just manipulate each column as you see fit?
    – sr28
    Commented Nov 3, 2016 at 17:03
  • I receive each string item as one string and not several so I would not know which word belongs to which column.
    – Harry Boy
    Commented Nov 3, 2016 at 17:09

2 Answers 2

3

You will probably have to change the font of your DataGrid, try a monospaced font like Courier, Courier New, Lucida Console, Monaco or Consolas. You can also go to your Notepad++ and find the font it is using if you want the same look and feel.

1
  • 1
    _dataGrid.FontFamily = new FontFamily("Courier New"); _dataGrid.FontSize = 12.0;
    – Harry Boy
    Commented Nov 3, 2016 at 17:29
0

You can print to concolse using a string format and alignment like this

 Console.WriteLine(String.Format("{0,10}  {1,20} {2, 30}"),
          str1, str2, str3));

where str1,str and str3 are the fields you want to print

1
  • I am not sure of how many fields I will receive, I simply receive a line of text.
    – Harry Boy
    Commented Nov 3, 2016 at 16:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.