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
1
vote
0answers
15 views

Generating HTML for prerolled d20 RPG initiative tables

A fairly simple program that I tried to write in Common Lisp in order to practice/learn. I'm sure this can be done more elegantly but Lisp's string handling seems to be very werd. ...
1
vote
1answer
69 views

Constructor function for persons with hobbies

I'm trying to write a constructor function that generates instances of a user. One of the properties of the user class is an array of the user's hobbies. I'd like ...
7
votes
2answers
913 views

`printf` improvement with C++ variadic templates

I am currently working through learning C++'s variadic templates and I wanted to create an example use of them that is less trivial than the one in my book. I decided to create a modification of ...
3
votes
1answer
54 views

Date format function in JavaScript

How can I improve the date format function. I have written in javascript (ES5/ES6)? This code is just a part of an exercise. ...
2
votes
1answer
55 views

Image Processing - Comparing 2 images and Ranking Similarity

My code compares 2 images of any shape/dimension and ranks them in order of similarity. It starts with reading from a CSV file with columns image1, image2 which contain absolute paths and then ...
2
votes
2answers
49 views

HackerRank Time Conversion solution

The challenge (PDF) is to convert a time from 12-hour format (hh:mm:ssAM or hh:mm:ssPM) to 24-hour format. This is my solution, ...
15
votes
2answers
2k views

Message-formatting code with pluralization, revised to be more functional

I'm a C++ dev, and I've recently started working my way through Clean Code*. Whenever I encounter an example I think I could improve, I try to re-implement it in C++. On pp. 28-29 there is an example ...
4
votes
2answers
75 views

Displaying IP addresses in Go using Stringer interface

I am trying out some Go code examples (while coding a private project) to get more "in-depth" knowledge about the language. I have come across an exercise from the Go Tour website about displaying ...
4
votes
1answer
49 views

Pivotting SQL Table Response to JSON in JavaScript

Issue Our API returns two formats JSON and this SQL table format. I'm not sure what it is truly called so I'll give a few examples below. Like all API responses, it can be a list or a single response ...
1
vote
1answer
73 views

Format double to 3 decimal places without decimal separator to a certain length

I need to format a double value to three decimal places to a string with length of 9 with leading spaces and no decimal separator. My approach is this ...
4
votes
2answers
136 views

Print a pattern of text based on a line from an Excel file

I started to learn Python not long ago to automate certain tasks I work on. I want to optimize a script I wrote that takes a line in an Excel file and prints a pattern of text based on this line's ...
7
votes
3answers
202 views

Convert integer to full text string duration

I have a function I have written in VB for use in SSRS 2012. It takes an integer and converts it to full text duration - for example 900 becomes "15 minutes", 9000 becomes "2 hours 30 minutes", and ...
5
votes
3answers
184 views

Encapsulating snprintf to avoid repetition of sizeof

Correct usage of snprintf involves very long and repetitive lines: ...
3
votes
1answer
75 views

Left or right padding a string with the specified character

Can I improve performance of below method? Is there anything I need to optimize or any redundancy I need to remove to make it more efficient? It's a simple method used to pad strings by left or right. ...
5
votes
2answers
685 views

Printing a multiplication table in C [closed]

I'm a complete beginner, but I'd like to learn how to program. I really started 2 weeks ago. So I tried the common exercise, aka the multiplication table, but I tried to add little things I learnt ...
4
votes
1answer
49 views

Print a Connect 4 grid based on some rules for each cell

In a game of Connect4: we start with an empty grid two players place pieces X and O on the grid the first player to achieve 4 pieces in a line wins! this is a text based console game Here is the ...
3
votes
1answer
47 views

Apply same format function to each python print() parameter

I have a python print statement and inside the string I wish to print are four digits. I would like to apply the same formatting function to each param. I am not ...
5
votes
2answers
406 views

Fantasy game inventory — Ch. 5 Automate the Boring Stuff

Here is a practice exercise — Fantasy Game Inventory \$-\$ You are creating a fantasy video game. The data structure to model the player’s inventory will be a dictionary where the keys are string ...
5
votes
2answers
112 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 ...
4
votes
1answer
106 views

A small PHP library for styling terminal output

I've attempted to make a small PHP library for styling terminal output using ANSI escape sequences. The repo is located here. To be honest, I am not really satisfied with the current structure of my ...
5
votes
2answers
146 views

Splitting an amount of money equally between a group of people

I'm building a clone banking app at the moment, and one of the things I'm trying to do is add Split Transaction (which can then be shared with a set of friends paying a given amount each). Initially, ...
3
votes
0answers
21 views

Formatting CSV as a table using BDD

This is the problem: Write a function to create a table from CSV data. The input to the function is a list of strings. Each string is formatted as a CSV record. Here’s an example for a ...
7
votes
1answer
631 views

Python program to convert a 24 hour format to 12 hour format

Given a string in a 24 hour format the program outputs a 12 hour format. The rules are: The output format must be 'hh:mm a.m.' if it represents before midday and 'hh:mm p.m.' after midday When the ...
4
votes
1answer
267 views

Converting long values in Java to unsigned strings

This one is a research attempt to find out how to convert long values as unsigned long integers to Strings. It is much slower ...
5
votes
1answer
103 views

Custom lexer/parser-based code prettifier

I'm adding rather extensive xml-doc comments to all Rubberduck inspection classes, like this: ...
11
votes
4answers
767 views

Cropping a message using array splits

I am trying to write a simple function to crop a given message to a specific length but at the same time not to cut the words in between and no trailing spaces in the end. Example: Input String: ...
4
votes
1answer
32 views

Calculating elapsed time

The code below compares recv.rcpt_dtim (which is a datetime type) against the current date/time. It calculates an elapsed time resulting in hours and minutes formatted like: "04:22". It took me a ...
7
votes
2answers
142 views

Register “%b” conversion specifier

I'm writing a library to register the b, B conversion specifiers and make them work the closest possible to ...
1
vote
2answers
43 views

Trimming strings in non-contiguous spreadsheet ranges

This code is tested and works, but I am needing some guidance on simplifying these loops with non-contiguous ranges. I was thinking an array might be better, but I ...
2
votes
1answer
57 views

256-bit ASCII Color Encoded Hex Dump in C

I made this hex dump after being dissatisfied with the free hexdumps out there. The biggest dissatisfaction is that the encodings for the char bytes were not color encoded, just like the hexyl hexdump ...
3
votes
2answers
74 views

Function to format numbers with thousand separators and decimals

I've wroted this function because I was getting trouble using toLocaleString() in google-apps-script, and after some refactorings I got to a working code: ...
7
votes
3answers
477 views

Split coins into combinations of different denominations

I have 3 types of coins: Gold, Silver, Copper. 1 silver = 100 copper. 1 gold = 100 silver. My input is always in coppers, and I want to be able to make it a bit more readable. So far my code is: ...
5
votes
3answers
140 views

Regex match comments and quotes

UPDATE New regex - covers escaped slashes and uses lazy qualifiers: ...
3
votes
1answer
55 views

/proc/net/tcp results filter and converter

Being unable to easily read the output of /proc/net/tcp I made a small C# console app that modifies the output to be in decimal notation instead of the standard hexadecimal, show the corresponding ...
0
votes
1answer
63 views

Formatting milliseconds as days, hours, minutes, and seconds [closed]

This is a function which aims to convert an amount of milliseconds to a more human-interpretable Day(s) Hour(s) Minute(s) Second(s) format: ...
5
votes
1answer
61 views

Indenting and dedenting ASP Classic code with Python

I've created a Python script that tries to properly indent and dedent ASP code. Similar to http://www.aspindent.com/ Since I've began using it I've noticed some edge cases that I hadn't anticipated. ...
2
votes
1answer
40 views

Get _m_s time format from milliseconds value

I could have any value in milliseconds like: 1040370 I must alert a specific converted time format : _m_s (ie:17m20s) Here ...
7
votes
2answers
67 views

Method for formatting a decimal number in Python using the given maximum number of digits and decimal places

The question itself should be fairly self-explanatory. My method takes in value, max_digits, and ...
1
vote
0answers
19 views

Extract and manipulate date from SharePoint and export into Google Charts

I am extracting a list of data from a SharePoint library with CSOM, then manipulating the data to give some sort of visible statistic through Google Charts. The data is a list of each parent ...
5
votes
3answers
89 views

Displaying elements of a list, in columns

I have a list of strings. I need to list them in rows and columns. Each row should not have more than "cols" number of values. Each of the values in a given row should be "step" away from the previous ...
2
votes
2answers
59 views

Adding punctuation to US and European patent numbers

I want to add custom punctuations in a given string. eg: ...
1
vote
2answers
90 views

Pretty print an object - JavaScript

I've written a function to prettify a json object, as if it were using JSON.stringify. I'm only focused on strings and other objects, nothing else. Is there a better way of doing this? perhaps using ...
3
votes
2answers
262 views

Adding thousand separator to various number types

Am making a pure .net library with helper functions (GitHub). However I wanted to have a thousand separator for all number types and here is what I am currently doing ...
2
votes
2answers
128 views

Formatting a price in Swift using an extension vs. a class

I have a price as a Double, which I should format it as a String. Should I use an extension instead of classical class to ...
3
votes
1answer
87 views

Formatting time delta

Quite often, I find myself measuring how long some part of my code takes to complete. I normally do that by storing current time using time.time() and then ...
11
votes
3answers
105 views

Simple generic auto __repr__

Preface At some point I was tired of writing & supporting __repr__ methods, so I've decided to write it once and reuse everywhere in my classes. Since I'm ...
2
votes
3answers
80 views

Printing integers with spaces between the digits

Problem: Given an integer between 1 and 32767 print the individual digits with 2 spaces between them. I am using C How To Program but this is not homework. The book has not gotten to arrays or ...
1
vote
1answer
147 views

Angular component to render currency or date values

I have an Angular component and it is just a label which renders a value and if it has an associated pipe, the output of the pipe should be rendered as value of the label. But I don't want to declare ...
5
votes
3answers
112 views

K&R C book, Exercise 1-21: Replace tabs with spaces

I'm new to C, just started reading K&R C book, and am working through exercises. This is my solution to 1-21, and as far as I tested it works. Anything that I'm doing wrong, or that it's not ...
3
votes
1answer
66 views

Polynomial implementation in Golang

I am writing a numerical analysis library in golang for which I need to implement a polynomial struct. Here is the source code: ...