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
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
3answers
270 views

Formatting the opposite of some numbers, with decimal alignment

Background I have a list of strings containing numbers. Each string is 8 characters long. For example : ...
1
vote
1answer
67 views

Object formatter using reflection

I am making an object formatter for use when debugging. Formatted class: ...
4
votes
1answer
215 views

Generating and printing chess board in Rust

This is the beginning of a chess program I'm writing in Rust. I'm new to Rust, so while this program works, I'm sure there are many improvements that could be made. For instance, I wanted to declare ...
8
votes
2answers
2k views

Checking some rules before a Telegram bot replies to a message

So far, I've created a couple of programs, and the issue that comes up is how ugly and non-scalable they look. For example, currently I'm working on a telegram bot. Before replying to a message I ...
4
votes
2answers
202 views

Entab.c - Program that replaces string of blanks by the min # of spaces & tabs to achieve identical output

This is Exercise 1-21 of K&R (2nd edition). I've seen someone else's post about it but it doesn't solve the problem the way my code does, and I wasn't sure whether I was allowed to post my code ...
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. ...
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 ...
2
votes
0answers
50 views

Display results from a JSON response based on game type

This code currently works with no errors. I want to know if there is a way to improve its conding structure, as there is a lot of repetition and it looks really bad. I tried an alternative way by ...
9
votes
1answer
3k views

Stopwatch class in C++

I needed to implement a stop watch like class that will be used to measure running time of different functions by others. The final running time needs to be printed in 9h 3min 2s 23s 32ms 87us 78ns ...
2
votes
0answers
229 views

Convert python's strftime directives to user-friendly format examples

I'm converting python's very un user-friendly strftime date time directives to user-friendly formats so that users of an API will know how to format a date if they send an invalid format. My thinking ...
6
votes
1answer
2k views

Custom ostream for a println-like function

I am writing a plugin in C++ that uses C API that gives me a single logging function with this signature: typedef void(*println_t)(const char* text); I want to ...
7
votes
1answer
604 views

Elegant output separators

Today I found myself reinventing output separators for the zillionth time. I have converged on an approach like the following that seem pretty clean: Live On Coliru ...
8
votes
3answers
95 views

Drawing a table for data from file

I wrote a function for drawing a table for data that comes from file: ...
1
vote
1answer
2k views

Formatting date difference in human-friendly terms

I've written a function to take the difference between two dates and display it in a particular format. I've used a lot of if-else statements, which seems a little ...
4
votes
1answer
549 views

The sheet music of Morning Mood

While learning to play the keyboard, I find it helpful to write down the score of the pieces I play, regardless of whether a score already exists. The code is written using Frescobaldi as IDE and ...
3
votes
1answer
174 views

Formatting mm:ss to string with Javascript

I have a function that takes a time of minutes and seconds, and converts it to a string in the following way: '0:30' would become '30 Seconds', '1:30' would become '1 minute 30 seconds', '2:01' would ...
5
votes
1answer
95 views

Printing limits of Integral Types in C

I intend to demonstrate the proper way to use format specifiers for different data types and also display the respective limits. This is meant to be an example. ...
1
vote
0answers
90 views

Echo in Prolog with single print (new version)

In order to learn a bit more of Prolog, I implemented the echo command for SWI-Prolog. I want a correct implementation, that is, it satisfies the following requirements: It makes only one I/O call ...
7
votes
1answer
105 views

A database of books, part 1

Backstory I collect books. A lot of books. Whitepapers, (programming) cookbooks, transcripts, important letters, overviews, you name it. Usually in PDF, otherwise my house would be too small. To keep ...
0
votes
2answers
89 views

Formatting a string in Python with three possible replacement fields

I'm looking for a much simpler way of formatting a string in Python which will have a different number of replacement fields in different cases. Here's what I'm doing now, which is working fine: <...
0
votes
2answers
92 views

Knowing which way to iterate the for loop C

I want the code to automatically know which way to iterate through the loop without manually adding the '>' or '<' sign. I am using the logic that if the setup part of the loop is smaller than the ...
4
votes
1answer
240 views

C++ with Qt - Conversion of angle in radians to DDD°MM′SS.FFF″ string

I had to write a function which takes an angle in radians and precision N as input and returns a string representation of its magnitude in the format DDD°MM′SS.FFF″ ...
9
votes
4answers
9k views

Format an integer with thousands separator (recursive implementation)

The function accepts a number n and displays it recursively with commas. As well as a general code review, I'm interested in suggestions for alternatives to ...
1
vote
1answer
244 views

Round a number and replace trailing zeros by spaces

Goal From a number x, I would like a string of the rounded value at n decimals and replace each trailing zeros by a space. ...
2
votes
1answer
63 views

Printing complex function results output using text formatting builder

I'm working on a benchmarking library. The code below is a textual serializer of a complex benchmark results structure (there will be more fields). Main feature is building up the desired output ...
1
vote
1answer
70 views

Mail merge (Parsec string formatting) example

My intent is to perform "mail merge" where I can write strings like "hi <<name>>" and format them according to a ...
1
vote
3answers
240 views
1
vote
1answer
171 views

Formatting floating point number as mixed fractional in Ruby

I have to format numbers that are either whole numbers or mixed fractional numbers with quarters (1/4, 1/2, 3/4) or thirds (1/3, 2/3). The numbers are given as floats, for example ...
4
votes
3answers
263 views

Custom date data type in C

I've created a very basic date data type in C simply to practice writing my own data type. Please critique. ...
6
votes
2answers
679 views

Converting tcpdump output to text2pcap acceptable input

I have some text file in following format (network traffic collected by tcpdump): ...
6
votes
2answers
14k views

Convert seconds to hours/minutes/seconds and pretty print

I'm self taught in python 3, and I frequently keep track of how long my scripts have been running using the time library. ...
3
votes
2answers
62 views

Composing URLs for fetching passenger fares from multiple providers

Can someone give me advice, how to make this code look nice? ...
1
vote
0answers
55 views

Recursive time formatter

This is small utility class I made format.utility.ts. There are some other one off utility methods in here I removed for this. The one in question is ...
7
votes
2answers
1k views

Convert Lua UINT to hh:mm:ss

I have found the convert_to function in the lua-user wiki, and I created the convert_to_time function which does what I want it to do. Which is, basically: Having a number, return its value in a Time ...
6
votes
1answer
5k views

Named placeholders filling and extraction in Java

Here's utility class that is capable of filling strings with placeholders and extract values of placeholders from filled strings. Placeholders are enclosed in % ...
5
votes
1answer
283 views

Draw a directory tree

My goal was to create a simple-to-use CLI program for drawing directory trees (what tree does on most platforms, basically). I'm submitting my 'backend' program for ...
6
votes
3answers
1k views

Pretty-printed tables in Haskell

Purpose A clean, reusable module to generate pretty tables (much like those in SQL-clients), like so: ...
5
votes
1answer
66 views

Aligning fstab columns

I know I can use the unix column function to replicate 90% of the functionality here, so this is mostly just to practice python. I find a misaligned fstab file really hard to read. This script parses ...
1
vote
1answer
4k views

Text-wrapping function in JavaScript

I have the following code on my server that takes a string and inserts newlines in such a way that the string is separated into lines, all of which are shorter than ...
6
votes
1answer
644 views

Python word wrapping function

I'm attempting to make some ui tools for my python ncurses application, and I needed a word wrap function. It works pretty well, but trying to read it is frustrating. I'm specifically looking for ...
8
votes
1answer
25k views

Python class initialize with dict

how can I express this idea in Pythonic way? The problem is that I want to create class with many attributes, but don't want to initialize all in __init__(self, arg1, arg2, ..., argN). Instead of this ...
2
votes
1answer
158 views

Converting date format in range of cells

This code works, but I was wondering if there's a way to get excel to identify the date data more easily. This comes from an imported file where the date field(s) come in as text and in a European ...
3
votes
0answers
4k views

Regex credit card expiry date auto format

I'm trying to write a function that will get content from input element and try to format numbers entered in input box in MM/YY. Following is a solution that I have, and I want to reduce the number of ...
3
votes
1answer
580 views

Indian numbering system formatting

The following code converts a number into Indian numbering system format. I know locale can also help in getting similar format but I wanted something that can work on any system because not all ...
1
vote
1answer
643 views

Output a flight schedule, formatted in military time

I have a CVRP problem that I solved in Python. There are 6 planes (T1-T6) and 3 airports (AUS,DAL,HOU). The airports have 1,2,3 gates respectively. Each airport has a minimum ground time of 25, 30, 35 ...
11
votes
2answers
8k views

Printing a calendar for a month based on user input

I have a long piece of code that has many repeating points. I am sure that it doesn't take this amount of code to create a simple calendar, but I do not know how to shorten this piece of code. ...
7
votes
1answer
1k views

Python 3.x Hexdump

I posted a small hexdump generator function from a program I've been writing not long ago and applied what a reviewer suggested since then. The goal was to lazily hexdump bytes objects (byte strings, ...
5
votes
1answer
311 views

Parse and format date

I have the following code for taking a date in the form of a string yyyy-MM-dd HH:mm:ss (UTC timezone) and turning it into ...
5
votes
1answer
191 views

Wrap string at certain delimiters

The method receives an unformatted string and it needs to put line breaks after ';' or before 'i)' and 'i.', where i - integer. If received a string like '; 1)', then it should add only one line ...

1 2 3
4
5
11