logo
down
shadow

Very tricky/complex text formatting: How can I output a string[][] as a table?


Very tricky/complex text formatting: How can I output a string[][] as a table?

Content Index :

Very tricky/complex text formatting: How can I output a string[][] as a table?
Tag : chash , By : orneka
Date : December 01 2020, 05:00 PM

may help you . First of all, it is better to keep the formatting logic in the OutputFormatter class instead of just using a constant value from it.
The following code should work for you.
public class OutputFormatter
{
    public const int OutputMaxLength = 16;

    public static string[] Format(string output)
    {
        int offset = 0;
        List<string> outputParsed = new List<string>();
        while (offset < output.Length)
        {
            outputParsed.Add(output.Substring(offset, Math.Min(OutputMaxLength, output.Length - offset)));
            offset += OutputMaxLength;
        }
        return outputParsed.ToArray();
    }
}

private static string[][] strings = { 
        new string[] {"CompareLastTwo","Shows difference between friends lists of last two Facebook data files in repository"},
        new string[] {"AddFriendList <DataFolderPath>", "blah blah blah"}
    };

public static void Main(string[] args)
{
    foreach (string[] pair in strings)
    {
        string[] value0 = OutputFormatter.Format(pair[0]);
        string[] value1 = OutputFormatter.Format(pair[1]);

        int maxRows = Math.Max(value0.Length, value1.Length);
        string template = "{0," + OutputFormatter.OutputMaxLength + "} | {1," + OutputFormatter.OutputMaxLength + "}";
        for (int row = 0; row < maxRows; row++)
        {
            Console.Write
            (
                template,
                value0.Length > row ? value0[row] : null,
                value1.Length > row ? value1[row] : null
            );
            Console.WriteLine();
        }
        Console.WriteLine(new string('-', OutputFormatter.OutputMaxLength * 2));
    }
}

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Tricky table formatting in css


Tag : html , By : DonMac
Date : March 29 2020, 07:55 AM
it helps some times jsFiddle: http://jsfiddle.net/fQvLv/1/
CSS
.level-one-left{
    border:2px solid #000; 
    border-right:1px solid #000;
}
.level-one-right{
    border:2px solid #000; 
    border-left:1px solid #000;
}
.level-two-left{
    border:2px solid #000; 
    border-right:1px solid #000;
    border-top:0px;

}
.level-two-right{
    border:2px solid #000; 
    border-left:1px solid #000;
    border-top:0px;
}
.left-side{
    border-left:2px solid #000;  
}
.right{
    border-right:2px solid #000;
}
.top{
    border-top:2px solid #000;
}
.bottom{
    border-bottom:2px solid #000;
}
<table cellspacing="0">
    <tr>
        <td style="border:0"></td>
        <th class="level-one-left" colspan="5">Level One</th>
        <th class="level-one-right" colspan="3">Level One</th>
    </tr>
    <tr>
        <td></td>
        <th class="level-two-left" colspan="5">
            <table>
                <tr>
                    <th>Level Two</th>
                    <th>Level Two</th>
                    <th>Level Two</th>
                    <th>Level Two</th>
                    <th>Level Two</th>
                </tr>
            </table>
        </th>
        <th class="level-two-right" colspan="3">
        <table>
                <tr>
                    <th>Level Two</th>
                    <th>Level Two</th>
                    <th>Level Two</th>
                </tr>
            </table>
        </th>
    </tr>
    <tr>
        <th class="left-side top right">Test One</th>
        <td>Content</td>
        <td>Content</td>
        <td>Content</td>
        <td>Content</td>
        <td class="right">Content</td>
        <td>Content</td>
        <td>Content</td>
        <td class="right">Content</td>
    </tr>
        <tr>
        <th class="left-side right">Test Two</th>
        <td>Content</td>
        <td>Content</td>
        <td>Content</td>
        <td>Content</td>
        <td class="right">Content</td>
        <td>Content</td>
        <td>Content</td>
        <td class="right">Content</td>
    </tr>
        <tr>
        <th class="left-side right">Test Three</th>
        <td>Content</td>
        <td>Content</td>
        <td>Content</td>
        <td>Content</td>
        <td class="right">Content</td>
        <td>Content</td>
        <td>Content</td>
        <td class="right">Content</td>
    </tr>
        <tr>
        <th class="left-side right">Test Four</th>
        <td>Content</td>
        <td>Content</td>
        <td>Content</td>
        <td>Content</td>
        <td class="right">Content</td>
        <td>Content</td>
        <td>Content</td>
        <td class="right">Content</td>
    </tr>
        <tr>
        <th class="left-side right bottom">Test Five</th>
        <td class="bottom">Content</td>
        <td class="bottom">Content</td>
        <td class="bottom">Content</td>
        <td class="bottom">Content</td>
        <td class="bottom right">Content</td>
        <td class="bottom">Content</td>
        <td class="bottom">Content</td>
        <td class="bottom right">Content</td>
    </tr>
</table>

Problems aligning text in a table using string formatting


Tag : python , By : user109285
Date : March 29 2020, 07:55 AM
wish helps you Your code doesn't make much sense - you're calculating Fahrenheit over a different range to Celsius. Try:
for c in range(40, -41, -1): # iterate over Celsius
    f = (c * (9 / 5)) + 32 # calculate Fahrenheit from Celsius
    print("{0:d}\t{1:.1f}".format(c, f)) # print both in one line, tab-separated

C# formatting sql table date column output when writing to text file


Tag : chash , By : UpperLuck
Date : March 29 2020, 07:55 AM
This might help you You could try this - I've also added an additional case to format any decimal values to currency format.
foreach (DataRow row in data.Rows)
{
    for (i = 0; i < row.ItemArray.Length; i++)
    {
        if ( row.Table.Columns[i].DataType == typeof(System.DateTime))
            sw.Write( ((DateTime)(row.ItemArray[i])).ToString("dd/MM/yyyy") + "\t | ");
        else if ( row.Table.Columns[i].DataType == typeof(System.Decimal))
            sw.Write( ((decimal)(row.ItemArray[i])).ToString("C") + "\t | ");
        else
            sw.Write(row.ItemArray[i] + "\t | ");
    }
    sw.WriteLine();
}

String types and text output formatting


Tag : javascript , By : cthulhup
Date : March 29 2020, 07:55 AM
Does that help Keeping Line-Breaks
For preserving line-breaks, the issue is text based line breaks (carriage return, \r, or newline, \n) are ignored in HTML. The best ways to create spacing between lines is to either use the dedicated "line break" element, or separate text into individual elements and add spacing with CSS.
function SendEmail() {

    var formResponseSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Response");

    // fetch entry
    var messageRange = formResponseSheet.getRange("D" + formResponseSheet.getLastRow());

    // build message
    var message = {
        to: "destination@email.net",
        subject: "New Entry Posted",
        htmlBody: 'Hello, a new entry was posted.<p>' + messageRange.getValue().replace(/[\r\n]{1,2}/g,"<br>") + "</p><a href=\"www.some_link.com\">Link here</a>."
    };

    // send
    MailApp.sendEmail(message);

}

Converting Python complex string output like (-0-0j) into an equivalent complex string


Tag : python , By : S. Fenz
Date : March 29 2020, 07:55 AM
I wish this helpful for you As @wim has noted in the comments, this is probably not the right solution to the real problem; it would be better to not have converted those complex numbers to strings via str in the first place. It's also quite unusual to care about the difference between positive and negative zero. But I can imagine rare situations where you do care about that difference, and getting access to the complex numbers before they get str()'d isn't an option; so here's a direct answer.
We can match the parts with a regex; [+-]?(?:(?:[0-9.]|[eE][+-]?)+|nan|inf) is a bit loose for matching floating point numbers, but it will do. We need to use str(float(...)) on the matched parts to make sure they are safe as floating point strings; so e.g. '-0' gets mapped to '-0.0'. We also need special cases for infinity and NaN, so they are mapped to the executable Python code "float('...')" which will produce the right values.
import re

FLOAT_REGEX = r'[+-]?(?:(?:[0-9.]|[eE][+-]?)+|nan|inf)'
COMPLEX_PATTERN = re.compile(r'^\(?(' + FLOAT_REGEX + r'\b)?(?:(' + FLOAT_REGEX + r')j)?\)?$')

def complexStr2str(s):
    m = COMPLEX_PATTERN.match(s)
    if not m:
        raise ValueError('Invalid complex literal: ' + s)

    def safe_float(t):
        t = str(float(0 if t is None else t))
        if t in ('inf', '-inf', 'nan'):
            t = "float('" + t + "')"
        return t

    real, imag = m.group(1), m.group(2)
    return 'complex({0}, {1})'.format(safe_float(real), safe_float(imag))
>>> complexStr2str(str(complex(0.0, 0.0)))
'complex(0.0, 0.0)'
>>> complexStr2str(str(complex(-0.0, 0.0)))
'complex(-0.0, 0.0)'
>>> complexStr2str(str(complex(0.0, -0.0)))
'complex(0.0, -0.0)'
>>> complexStr2str(str(complex(-0.0, -0.0)))
'complex(-0.0, -0.0)'
>>> complexStr2str(str(complex(float('inf'), float('-inf'))))
"complex(float('inf'), float('-inf'))"
>>> complexStr2str(str(complex(float('nan'), float('nan'))))
"complex(float('nan'), float('nan'))"
>>> complexStr2str(str(complex(1e100, 1e-200)))
'complex(1e+100, 1e-200)'
>>> complexStr2str(str(complex(1e-100, 1e200)))
'complex(1e-100, 1e+200)'
>>> complexStr2str('100')
'complex(100.0, 0.0)'
>>> complexStr2str('100j')
'complex(0.0, 100.0)'
>>> complexStr2str('-0')
'complex(-0.0, 0.0)'
>>> complexStr2str('-0j')
'complex(0.0, -0.0)'
Related Posts Related QUESTIONS :
  • Pool of objects with objects that are already on the scene in advance
  • StatusBar text fade-out when binding using Caliburn.Micro
  • Queryfilter on ApplicationUser in OnModelCreating in ApplicationDbContext creates StackOverflowException
  • How to get record form a different table based on a value from first table with linq expression?
  • Show data in Grid from returned model
  • Using Attributes to Override Data Model Conventions
  • Basic OOP console calculator, result Error
  • Compositon and Repository pattern
  • Multiple using statements with if condition
  • How do i increase a number by 1 in every line that contain the number 1
  • Add binding to elements that are created in codebehind
  • How to add a column in an existing AspNetUsers table
  • Order a list of elements with another list of doubles
  • How to setup a NuGet package to copy content files to output build directory?
  • In SignalR Core using ChannelWriter: Do I need to call TryComplete twice if there's an exception?
  • C# GetProcessesByName: issue with colon
  • c# wpf | create complex object with user-defined name to Serialize into JSON
  • How can I get a instance of a generic list with reflection?
  • WPF XAML - Design time and visibility of textbox
  • EF Core and MySql query is too slow
  • Getting Registered App Display Name from an App Id
  • How to get all variables from a string
  • Delete entity with all childs connected
  • Azure Build agent cant´t find class library referance
  • Initialize Nested Dictionaries in c#
  • .Net Core Binding
  • Generic event test method, preventing code duplication
  • How do I keep the ellipses in the center when the screen is resized
  • How to require a property using JsonSchema.NET?
  • C# XDocument Element/Elements returns null
  • Autofac keyed service with IEnumerable relationship type
  • Installing EntityFramework via NuGet manager
  • Always Check if there is Internet Connection Xamarin forms
  • WCF OneWay service slows down when aspNetCompatibilityEnabled is set to false
  • Can we use JsonRequestBehavior.AllowGet with [HttpPost] attribute?
  • How to customize the Setup wizard with custom forms in Visual Studio setup project
  • C# ASP.NET - Use method from another class to create labels
  • C# List IList or IEnumerable as argument
  • Parsing File with C# And Replace method
  • Losing special unicode characters in encryption (C#)
  • Getting stored procedure returned value instead of row affected
  • How can I construct HTML using NameValuePair in android?
  • Loading a pop up page in ASP.net through a js file
  • How to pass alert or notification message from controller to View?
  • C# to pause, turn on ssas server, backup cube.... how to?
  • How to execute DataTable.Select() for a column of custom class type for a particular element in that C#
  • how to connect mysql8.0 with C#
  • Passing incorrect values into MultiValueConverter by MultiBinding
  • Can i use IEnumerator as Update func?
  • How to convert API Json response to C# Array?
  • Blazor Textfield Oninput User Typing Delay
  • Performing both layout and render transform results in wrong output
  • uwp beforetextchanged cursor moving in front of text
  • How to keep duplicates from a string[] exclude words from a List and print them out
  • .Net Core Strings.Asc/Mid/Chr/Len missing even after importing Microsoft.VisualBasic
  • How to return to previous search page without being asked to Confirm Form Re-submission and keeping the results on ASP.N
  • How set a identity scaffolding item/page how initial page in asp.net MVC core?
  • LINQ isn't calling Dispose on my IEnumerator when using Union and Select, expected behavior or bug?
  • What is "ByteArray.uncompress()" in AS3 equivalent to in C#?
  • Getting a specific letter from a string variable for my simple guessing game for clues
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com