Questions tagged [formatting]

A generic term meaning the process by which text transformed into a more meaningful or clearer output. A typical example would be the transformation of a decimal into a particular currency format with the correct number of decimal places.

Filter by
Sorted by
Tagged with
18
votes
3answers
2k views

A CSharpish String.Format formatting helper

A while ago I implemented .net's string.Format() method in VB6; it works amazingly well, but I'm sure there has to be a way to make it more efficient. I'll start ...
10
votes
4answers
494 views

C++ string Formatter

I had an uneventful afternoon, so I thought I might try and write a string formatter. This is based on the documentation I found here. ...
44
votes
2answers
906 views

Tool for creating CodeReview questions

To download the tool and for usage instructions, see the follow up to this question Description I have realized that there's a whole bunch of code I want to have reviewed, but copying file by file, ...
4
votes
0answers
134 views

C++ string Formatter Again Part-4

Previously asked here. The code is now available on GitHub. Since the previous review I have added unit tests. Since it is big it will come in a couple of parts. Part 1 | Part 2 | Part 3 | Part 4 ...
24
votes
1answer
334 views

Follow-up to tool for posting CodeReview questions

Description This is a follow-up question to Tool for creating CodeReview questions. Things that has changed include: Removed replacing four spaces with one tab, all tabs and all spaces in the code ...
5
votes
2answers
199 views

C++ string Formatter Again Part-1

Previously asked here. The code is now available on GitHub. Since the previous review I have added unit tests. Since it is big it will come in a couple of parts. Part 1 | Part 2 | Part 3 | Part 4 Part ...
4
votes
1answer
137 views

C++ string Formatter Again Part-3

Previously asked here. The code is now available on GitHub. Since the previous review I have added unit tests. Since it is big it will come in a couple of parts. Part 1 | Part 2 | Part 3 | Part 4 ...
4
votes
1answer
116 views

C++ string Formatter Again Part-2

Previously asked here. The code is now available on GitHub. Since the previous review I have added unit tests. Since it is big it will come in a couple of parts. Part 1 | Part 2 | Part 3 | Part 4 Part ...
10
votes
2answers
21k views

Pretty-print Pascal's triangle

...
12
votes
4answers
12k views

Align Strings for Output

I wrote a class which can format input so that it is properly aligned. I'm interested in all suggestions (regarding structure, usability, style, naming, comments, etc). I'm especially wondering ...
14
votes
2answers
1k views

Python ASCII-Art Table

As a part of a console utilities module, I created a function that takes a table in the form of an array of arrays, and generates an ASCII table with the given contents. I've also added the options ...
17
votes
5answers
5k views

Printing a list as “a, b, c.” using Python

Is there a better way to do this? Assuming very long lists, is this slow and wasteful? ...
40
votes
8answers
17k views

Rendering a person's time clock record in HTML, with many color-coded conditions

I have coded this mess of JavaScript and a bit of jQuery. Everything here works perfect as intended, however it is a real mess. What would be the best way to clean this up with best practices and ...
20
votes
4answers
29k views

Create a C++ string using printf-style formatting

It's often convenient to use C-style printf format strings when writing C++. I often find the modifiers much simpler to use than C++ I/O manipulators, and if I'm ...
10
votes
4answers
901 views

Console-based table structure: Revisited

This is a follow-up from my previous post, which can be found here. A readme for more detailed information can be found here. It is a library to create console based tables where you can insert, ...
20
votes
3answers
600 views

Formatted print without the need to specify type matching specifiers using _Generic

This code allows printing in C with a style similar to C++ ostream. By using _Generic() (see ...
8
votes
1answer
5k views

Integer-to-ASCII algorithm (x86 assembly)

This is my best effort at converting a 32 bit integer in EAX, to an 8 character ascii string (result in RDI). It will work ...
7
votes
2answers
3k views

writeln() and format() with variadic templates

I wanted to get better acquainted with variadic templates, so I decide to try to implement a function like D's writeln(), just for fun. ...
18
votes
2answers
4k views

Retro Rocket ASCII Art

Inspired by Nested for-loop ASCII art, I looked at building a more complicated ASCII art than just the normal 'diamond' and 'triangle' variations that crop up occasionally here. The challenge: ...
13
votes
5answers
6k views

Cleaning up date strings in Python

Working from a CSV of about 14.000 lines, I need to match dates in the CSV against some API. I'm reading the CSV using Pandas (for various other reasons). Most often, the date is just a year, i.e. an ...
10
votes
2answers
2k views

Tool for automatically correcting indentation and formatting of CR & SO code

This is my tentative solution to: How can I prepare my code so that I can paste it formatted? If you need to copy and paste code into the question or answer textarea when solving someone's problem, ...
27
votes
6answers
2k views

Formatter class

In our production code, we cannot use Boost or C++0x. Formatting strings using sprintf or stringstream is annoying in this case,...
12
votes
4answers
2k views

Prettify JSON class

It's not much, but I tried employing some of the things I learned yet never really got to use, since that kind of code isn't really needed where I work (for the most part). I tried making it as much C+...
8
votes
3answers
5k views

Format a timespan with up to two fields

I'm looking to achieve a time format that looks like this: 2d 4h remaining; or 1h 36m remaining; or 35s remaining, etc. So that it only displays the two largest values of time (this is how Clash of ...
7
votes
2answers
3k views

Bouncing a word left-right on screen

I made a Java program that asks for a word, then a screen width, then whether you want it to go fast or slow. Then it outputs that word and bounces it across the screen. Is this code efficient for ...
5
votes
2answers
1k views

Character Picture Grid exercise - automatetheboringstuff

Regarding the Character picture exercise located at the end the following page: https://automatetheboringstuff.com/chapter4/ Say you have a list of lists where each value in the inner lists is a ...
5
votes
1answer
1k views

Simple parsing for string formatting

Recently I submitted some string formatting and printing code (found here) that I wrote as an small exercise. It was implemented naively using string replacement. This time around I wanted to actually ...
5
votes
3answers
248 views

Encapsulating snprintf to avoid repetition of sizeof

Correct usage of snprintf involves very long and repetitive lines: ...
5
votes
3answers
2k views

PrettyPrint a Binary Tree

I was going through this tutorial for Pretty Printing a binary search tree and decided to implement my own version. Here is my implementation. This version works only for trees that are complete ...
4
votes
2answers
930 views

ExceptionPrettifier for prettier exception strings

I've been refining my previous idea for pretty exception strings and made the following changes: Exceptions can be ordered. Prints all properties including Data. ...
3
votes
2answers
841 views

Shortening and optimizing diamond-printing code

I'm working through a Java textbook by Paul and Harvey Deitel and I have come across a review question (Chapter 2 - Intro to Java, Exercise 2.18 for those that have the book) which asks the user to ...
1
vote
1answer
2k views

Format A TimeSpan With Years

I have a class with 2 date properties: FirstDay and LastDay. LastDay is nullable. I would ...
15
votes
2answers
1k views

K&R 1-21 write an “entab” program

From K&R exercise 1-21, Write a program entab that replaces strings of blanks by the minimum number of tabs and blanks to achieve the same spacing. Use the same tab stops as for detab. When ...
11
votes
1answer
1k views

Formattable Fraction

I have written this small little program, to test how my Fraction type behaves when used with and without a custom ...
11
votes
2answers
2k views

A fraction of the code

Following up on this post, and including some major changes suggested, here's the revised code. Changes include: No longer keeping an IFormatProvider at instance ...
10
votes
1answer
923 views

String-formatting and printing functions

As a small exercise I have written some string formatting and printing functions in C++11. I would like a bit of code review, not so much on the merits of using this over something like ...
9
votes
1answer
909 views

Simple parsing for string formatting (version 2)

This is my second attempt (version 1) at writing a string formatting utility which uses parsing. This time I more explicitly designed it as a finite state machine. I have very little experience with ...
8
votes
1answer
288 views

Pretty printing degrees input to radians

I'm mostly concerned about edge cases, although I think I dealt with them all. Improvements on code quality would also be much appreciated. ...
6
votes
2answers
369 views

Safe and simple strtol()

Until today, in the few cases where I needed something like this, it had been in simple programs which only I used, and where I didn't care about security, so I used the simple ...
5
votes
4answers
281 views

Helper function to format-output any type of variable

This question has already got some reviews, so I could partially improve my code: please look at my self-answer below, which also contains comments about the review. I'm frequently interested to ...
5
votes
5answers
417 views

Decimal Quantities needed to meet cost

I asked this question recently: Finding the number of capital letters in a word grouped by letter. The answerer answered my specific question so I have marked it as answered. However, I would like ...
5
votes
1answer
249 views

K&R Exercise 1-21. Write a program `entab` that replaces strings of blanks with tabs

Intro I'm going through the K&R book (2nd edition, ANSI C ver.) and want to get the most from it: learn (outdated) C and practice problem-solving at the same time. I believe that the author's ...
4
votes
2answers
557 views

K&R 1-20 Converting tabs to spaces using idiomatic C

I'm learning C with K&R 2nd Ed. I just completed exercise 1-20 (which is the detab program). I was hoping to get some feedback on my work. I want to make ...
3
votes
1answer
59 views

colorprint - An ANSI Escape sequence console writer mini-library

I wrote this a long time ago. I came back to it and decided to clean it up a little. It uses the preprocessor and C99 anon structs to make a flexible python-like ...
3
votes
1answer
67 views

Easy to use code preparation script for CodeReview questions

We all face questions that forget to include their code. Sometimes all of it, sometimes only parts, that make the rest of the question unfortunately incomplete and therefore off-topic. What if it was ...
3
votes
2answers
88 views

Displaying information extracted from an HTML table

This function below (used on a timeout due to my page loading time) displays information on my site. I grab this data from my table view that I load into the page. It is launched by clicking a button ...
3
votes
1answer
196 views

Extendable format provider

I needed a better string formatting options like ToUpper and ToLower but I also wanted to be able to use the default formattings ...
3
votes
2answers
761 views

Print multiplication tables

Write a function that given a max argument will print a nicely aligned multiplication tables, for example, if max = 8 ...
2
votes
2answers
89 views

Print a double as a decimal with a specified precision

How could I make this code more effective? ...
1
vote
1answer
4k views

Custom Exception.ToString() formatter

I find the default Exception.ToString() formattig very difficult to read especially if there are inner exceptions involved. I guess everyone knows how it looks: <...