Answered by:
Fixed Width Font for Code

Question
-
Visual Studio uses Fixed width font, so why can't these forums mimic what they will see. I just posted to the forum, my code with comments in the regex parse were no longer alinged and the final result shown in the comment did not line up due to the proportional font. GRRR Brent didn't you get new people to help?
string fromFile = @"Name 5 8 ID 30 31 Type 40 45 ICD 15 29 "; string pattern = @" ^ # Start looking at the beginning of the line (?!\s) # If white space at beginning, move to next line (?<Text>[^\d]+) # Valid text found extract it up to the first number (?<Start>\d+) # Get the starting index. (?:\s+) # Match but don't capture the space between (?<Stop>\d+) # Get the stopping index "; var result = Regex.Matches( fromFile, pattern, RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline ) .OfType<Match>() .Select( mt => new { Text = mt.Groups["Text"].Value, Begin = int.Parse(mt.Groups["Start"].Value), End = int.Parse(mt.Groups["Stop"].Value) } ) .OrderBy(rule => rule.Begin) .Select(rule => new { Text = rule.Text.Substring(0, Math.Min(rule.End - rule.Begin, rule.Text.Length)), Start = rule.Begin, End = rule.End, }) .Aggregate( new StringBuilder(), ( sb, rule ) => { var runningLength = sb.ToString().Count(); var padSpan = (rule.Start - 1); var padding = Math.Abs(runningLength - padSpan); return sb.Append( rule.Text.PadLeft( padding + rule.Text.Length ) ); } ) .ToString() ; Console.WriteLine( "12345678901234567890123456789012345678901234567890" ); Console.WriteLine( result ); /* Output 12345678901234567890123456789012345678901234567890 Nam ICD I Type */
William Wegerson (www.OmegaCoder.Com)
Answers
-
Yes, there is an indenting problem, I'll log a bug.
If I go to http://social.technet.microsoft.com/Forums/en-US/tnsandbox/thread/04190e1d-ff10-4c77-a47a-778c1beb75cc and copy the 2nd post into notepad, the first comment line is indented as 8 spaces as expected. Then I copied and pasted into VS and it formatted the ' This should be indented 8 spaces. line only four indented right under the If line above it. So even VS on a copy past adjusts the whitespace, reducing it by four or sticking the comment indented inline with the previous line starting point.
But you're right, we are dropping obvious spacing we should preserve. This is probably a bug in our colorization code we may be able to fix. I noticed in the sandbox thread your inserted code snippets aren't colorized, why is that, did you not chose a language, preview insert path to inserting it?
Community Forums Program Manager- Proposed as answer by Ed Price - MSFTMicrosoft employee Saturday, October 15, 2011 12:15 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Monday, November 7, 2011 10:01 PM
All replies
-
I'll take a look and see if there is something we can do to improve this. We may have a flaw in our css or the code that marks up the code.
Community Forums Program Manager- Edited by Brent SerbusEditor Thursday, July 14, 2011 5:46 AM edit
-
Yes, there is an indenting problem, I'll log a bug.
If I go to http://social.technet.microsoft.com/Forums/en-US/tnsandbox/thread/04190e1d-ff10-4c77-a47a-778c1beb75cc and copy the 2nd post into notepad, the first comment line is indented as 8 spaces as expected. Then I copied and pasted into VS and it formatted the ' This should be indented 8 spaces. line only four indented right under the If line above it. So even VS on a copy past adjusts the whitespace, reducing it by four or sticking the comment indented inline with the previous line starting point.
But you're right, we are dropping obvious spacing we should preserve. This is probably a bug in our colorization code we may be able to fix. I noticed in the sandbox thread your inserted code snippets aren't colorized, why is that, did you not chose a language, preview insert path to inserting it?
Community Forums Program Manager- Proposed as answer by Ed Price - MSFTMicrosoft employee Saturday, October 15, 2011 12:15 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Monday, November 7, 2011 10:01 PM
-
-
Yeah, but the spacing is still a bug...we'll look into that.
Community Forums Program Manager9 years since last post and is putting text in that need a fixed width font s this still a problem ?
I tried to put some text it is not code (output text from a console window) but still requires fix width font so columns align correctly how about an entry in language type "log" that would do this?I tried insert html button and using PRE tags but something is overriding the normal fixed width font implied by PRE tags. Other than using some text-to-html generator is the a way to do this that quick?
I am testing with Chrome and Firefox browsers, so is a compatibility issue with older browsers.
Below is insert code example - I see the text is not aligned as it is proportional font
Required OS version : B1 Image version : B2 Subsystem version : B3
Below is PRE tag example
Required OS version : B1 Image version : B2 Subsystem version : B3
Before I submit post it looks aligned but final result does not match
PRE tags are inheriting style from this css link - perhaps you could drop the override or explain why it is forcing proportional font.- Edited by Scott_R_ Thursday, April 9, 2020 11:57 AM