locked
Make the text in code brackets Fixed font RRS feed

  • Question

  • I work my hardest to align text in Visual Studio. But when I try to display it in the forums the proportional font screws it up. All code should be displayed as fixed.

    Here is an example, note the bottom should be aligned in column fashion as well as the regex comments...but woefully are not because of the proportional font used.

    string data = @"
    CHLORPHENIRAMINE 8MG CAP SA,
    CHLORPHENIRAMINE 12MG CP SA, 
    CHLORPHENIRAMINE 4MG TABLET, 
    CLEMASTINE FUM 2.68MG TAB, 
    CLEMASTINE 0.67MG/5ML SYRUP, 
    CLEMASTINE FUM 1.34MG TAB, 
    CYPROHEPTADINE 4MG TABLET, 
    CYPROHEPTADINE 2MG/5ML SYRUP, 
    DIPHENHYDRAMINE 50MG/ML SYN, 
    DIPHENHYDRAMINE(ELIXIR), 
    GENAHIST(LIQUID), 
    HYDRAMINE(ELIXIR), 
    Q-DRYL 12.5MG/5ML LIQUID, 
    ALLERGY 2% CREAM, 
    BANOPHEN ALLERGY LIQUID, 
    BANOPHEN 12.5MG/5ML ELIXIR, 
    DIPHENHYDRAMINE 25MG CAPS, 
    DIPHENHYDRAMINE 25MG CAP, 
    DIPHENHYDRAMINE 25MG CAPLET, 
    DIPHENHYDRAMINE 50MG CAPS";
    
    string pattern = @"
    ^(?<Drug>[^\s,]+\s?(?!\d|,)[^\s,]*) # This
     \s?                                # pound signs
     (?<Dosage>[^\s,]+)?                # should be
    \s?                                 # aligned
    (?<Form>[^\s,]+)?
    \s?
    (?<Release>[^\s,]+)?";
    
    
    var drugs = from Match m in Regex.Matches( data, pattern, RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline )
                select new
                {
                    Name    = m.Groups["Drug"].Value,
                    Dosage  = m.Groups["Dosage"].Value ?? string.Empty,
                    Form    = m.Groups["Form"].Value ?? string.Empty,
                    Release = m.Groups["Release"].Value ?? string.Empty
                };
    
    
    foreach ( var drg in drugs )
        Console.WriteLine( "{0,-30} {1,-10} {2,-10} {3}", drg.Name, drg.Dosage, drg.Form, drg.Release );
    /* Output:
    CHLORPHENIRAMINE               8MG        CAP        SA
    CHLORPHENIRAMINE               12MG       CP         SA
    CHLORPHENIRAMINE               4MG        TABLET
    CLEMASTINE FUM                 2.68MG     TAB
    CLEMASTINE                     0.67MG/5ML SYRUP
    CLEMASTINE FUM                 1.34MG     TAB
    CYPROHEPTADINE                 4MG        TABLET
    CYPROHEPTADINE                 2MG/5ML    SYRUP
    DIPHENHYDRAMINE                50MG/ML    SYN
    DIPHENHYDRAMINE(ELIXIR)
    GENAHIST(LIQUID)
    HYDRAMINE(ELIXIR)
    Q-DRYL                         12.5MG/5ML LIQUID
    ALLERGY                        2%         CREAM
    BANOPHEN ALLERGY               LIQUID
    BANOPHEN                       12.5MG/5ML ELIXIR
    DIPHENHYDRAMINE                25MG       CAPS
    DIPHENHYDRAMINE                25MG       CAP
    DIPHENHYDRAMINE                25MG       CAPLET
    DIPHENHYDRAMINE                50MG       CAPS
     * */

    • Edited by OmegaMan Wednesday, January 6, 2010 8:56 PM Better code example
    Wednesday, January 6, 2010 8:52 PM

All replies

  • This would be a huge help!  I agree that this would be a very nice improvement.
    Reed Copsey, Jr. - http://reedcopsey.com
    Wednesday, January 6, 2010 9:01 PM
  • What is interesting is that if one does a preview in the code popup...the preview uses fixed font . But once its submitted back to the page...the CSS of the page font in code is different from what is shown by the preview.
    William Wegerson (www.OmegaCoder.Com)
    Wednesday, January 6, 2010 10:33 PM