c# - String.Format won't create correct spacing, exhausted every method -


This may sound like a trivial question, but I swear that I can find every method. I am trying to output the content of a dictionary into a textbox. It's written in C # idak how relevant it is, but I'm producing for a WPF text box. I have tried the following methods:

  dictionary < String, int & gt; NGramDictionary = Statistical breakdown. GetgraFrequency (file path, 3); MasterStatsTextBlock.Text + = "~ N-gram Frequency ~" + "\ r \ n"; Leading (var KVP in EnvironmentWeek) {Masterstatstextblocks. Text = = string.format ("{0, -40} {1} {2}", kvp .k, kvp value, environment.newline); } MasterStatsTextBlock.Text + = "\ r \ n";   

and

  dictionaries & lt; String, int & gt; NGramDictionary = Statistical breakdown. GetgraFrequency (file path, 3); MasterStatsTextBlock.Text + = "~ N-gram Frequency ~" + "\ r \ n"; Leading (var kvp in ngdid) {masterstatstextblocks. Text = = string.format ("{0} {1} {2}", KVPK padrite (-40), kvp value, environment.NewLine); } MasterStatsTextBlock.Text + = "\ r \ n";   

and

  dictionaries & lt; String, int & gt; NGramDictionary = Statistical breakdown. GetgraFrequency (file path, 3); MasterStatsTextBlock.Text + = "~ N-gram Frequency ~" + "\ r \ n"; Leading (var kvp in ngramDictionary) {Masterstats Tetbelka. Text = = string.format ("{0} \ t \ t \ t {1} {2}", kvp .k, kvp value, environment. New line); } MasterStatsTextBlock.Text + = "\ r \ n";   

Neither work nor everyone will swear that they will work, but they do not. What does my production look like with the three:

  ~ n-gram frequency ~ locking keek book 1 of the mormon 1 book 1's cancer book 1 morning of 1 mormon 1 a.m. 1 a.m. extraction 1 TT Extraction Nifty 1 Extraction Nifty Nefie 1 Nephi Nephil 1 Nephir Swami 1 Lord says 1 speaks to 1 master 1 tells his children 1 his child 1 child Savior 1 savior teaches 1 guard teaches in simple way 1 Clear Rs. Teaches from 1 because   

please help me here at a loss seriously because why do not they work?

I suspect that you are using a textbox , and my guess is that you have not set the text in a monospace font. But you are trying to set up values ​​correctly to use string formatting.

To check string formatting, I instead work for the following demo string formatting, for a console app example. Both keys and values ​​have the maximum length, the key is left-to-proper and the value is correct:

  using the system; Using System.Collections.Generic; Class program {static zero main (string [] args) {var data = new dictionary & lt; String, int & gt; {{"First", 10}, {"second", 1}, {"third", 100000}}; Foreign currency (various entries in data) {console. Videline ("{0, -20} {1,8}", entry, entry, value); }}}   

Try it in your WPF UI and you will probably see the same breakdown - unless you set the font in monospace font.

However, the monospace font may look nicely ... In this case you do not want to use TextBox at all on this you can use other, There are more advanced text-based controls - or you can use a control that is more capable of displaying the grid of lists / data.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -