locked
Code block Fonts need to be monospaced / Fix Width RRS feed

  • Question

  • This is my yearly request for fixed with fonts in code blocks. Why is this still an issue?

    The below example is one I just used and *sigh* the

    1. #'s in the pattern don't line up
    2. The C# extension methods don't line up via the period(.).
    3. The final output doesn't line up by the :

    but they do in Visual studio.

    string data = @"Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;User ID=myDomain\myUsername;Password=myPassword";
    
    string pattern = @"
    (?<Key>[^=]+)    # Put the first text into the Key capture group
    (?:\=\s*)        # Match but don't capture the = and any space
    (?<Value>[^;]+)  # Get all text til the end of string which is not a ;
    (?:;?)           # Match but don't capture a ; if it exists";
    
            // IgnorePatternWhitespace only applies to the pattern so we can comment it; not regex parsing!
    Regex.Matches( data, pattern, RegexOptions.IgnorePatternWhitespace )
         .OfType<Match>()
         .ToDictionary( mt => mt.Groups["Key"].Value, mt => mt.Groups["Value"].Value )
         .ToList() // To do the foreach below
         .ForEach( kvp => Console.WriteLine( "{0,-20} : {1}", kvp.Key, kvp.Value ) );
        
            /* Output
    Data Source          : myServerAddress
    Initial Catalog      : myDataBase
    Integrated Security  : SSPI
    User ID              : myDomain\myUsername
    Password             : myPassword
                */
    

     


    William Wegerson (www.OmegaCoder.Com)
    Wednesday, December 21, 2011 6:55 PM

All replies