Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

5
votes
3answers
73 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
41 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: ...
3
votes
1answer
39 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
1answer
79 views

Circuit builder that calculates resistance/current/voltage

I am somewhat new to programming. I've written a program that takes user input accepting voltages and resistors, and calculating total resistance/current/voltage in the circuit. I am looking for ways ...
4
votes
0answers
43 views

Prettify phone numbers

I am a java developer and I am trying to learn Go. I tried to make a simple code that take numbers from a .txt file and make print them in a prettier format. That ...
2
votes
2answers
60 views

Print a double as a decimal with a specified precision

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

Generating Image & Serving via HTTP with Go

What is does I'm reading The Go Programming Language. Below is my code for the last exercise in the first chapter, which is to create a webserver, generate an image, and serve the image via the ...
3
votes
1answer
50 views

Printing (number, uncertainty) pair in a formal way

I am trying to do an auxilliary function to print pairs of value-uncertainty in a formal way, given their name, value and uncertainty. The "technical" agreement is that "uncertainty rules", meaning ...
1
vote
2answers
69 views

Simple ES6 Truncate method for character, word, and sentence limits

Simple truncating method for characters, words, and sentences for a personal utility library I've been working on. Improvements & criticism welcomed! Especially around default param usage, as I'...
5
votes
3answers
118 views

Hex dump of a list of 16-bit numbers

This is some code which prints a hexdump of a list of 16 bit numbers, at 16 bytes distance for each, after the "print data" comment: ...
2
votes
2answers
60 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 ...
6
votes
0answers
53 views

Edis: Emacs driven indentation script

Motivation I recently picked up Emacs. As part of the process, I've started to configure the editor to fit my needs with Emacs Lisp. The Elisp indentation rules are still foreign to me, so I pretty ...
3
votes
1answer
114 views

Simple stringifying using << operator

Background I wrote my_length class and some code. my_length can be stringified using ...
3
votes
1answer
46 views

Superscript all numeric characters after ^ in an excel cell

I have material property entries in a cell those look something like this: cell.value="O2 Permeability [cm^3/m^2]" The goal ...
0
votes
2answers
53 views

Function that adds commas between groups of 3 digits in a string

My program contains some very large integers and uses the GMP library. The output contains integers (probably small enough to fit into int). I would like to make ...
2
votes
3answers
65 views

Printing a monthly calendar on console

This is an implementation of mine to an exercise found in the book Core Java SE 9 for the Impatient. Goal is basically to print a monthly calendar by accepting month and year information from the user....
3
votes
1answer
40 views

Table Printer excercise

I'm new to Python and I came to the following excercise: Write a function named printTable() that takes a list of lists of strings and displays it in a well-organized table with each column ...
1
vote
1answer
49 views

K&R Exercise 1-22. Fold (break) lines at specified column

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 ...
0
votes
1answer
62 views

Taking text from a file and formatting it

My code takes numbers from a large text file, then splits it to organise the spacing and to place it into a 2-dimensional array. The code is used to get data for a job scheduler that I'm building. <...
5
votes
1answer
119 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 ...
11
votes
1answer
472 views

Pretty printing of the numpy ndarrays

Following this idea for pretty printing of numpy ndarrays, I have developed a very primitive prototype: ...
2
votes
2answers
142 views

Reformatting a date from YYYY-MM-DD to MM/DD/YYYY

In this small bit of JavaScript, a date is passed in as YYYY-MM-DD. It's formatted like this to be passed to the backend system. On the front end, we need to ...
2
votes
1answer
60 views

Printing a K-ary tree stored in level-order in an array

I am given an array that represents a k-ary tree (I am also given the branching factor "k") that is stored in level order. My task was to print the tree in level order. For example a trinary tree ...
2
votes
1answer
44 views

Justifying a string followed by a number

I started practicing on HackerRank to see how my learning is going on with Java. I wrote this code for problem which involved input having: String with maximum length of 10, followed by A 3 ...
2
votes
1answer
78 views

Java function to format seconds as minutes, hours, days

Anyone know how I write this code shorter, with modulos maybe? I also want to add weeks and years do this code, but it kind of got too long for that. Maybe there is some smart algoritm? Something in a ...
4
votes
3answers
572 views

Fancy padding of wide strings

I have a function that adds to a std::wstring some filler characters. The user gives a single filler character. They can also optionally given an initial filler ...
0
votes
1answer
42 views

Logging util with static lambda function

So again, I am a bit confused about some notes that i'am getting from my reviewer. I have some kind of utils, to print/prepare log messages. Yea, maybe I am a bit fanatic java 8 lambda guy but I think ...
1
vote
3answers
118 views

Convert integer to decimal string

I have a need to do some conversions in a loop to display the results using C++98 on Linux, which doesn't have any itoa() to complement ...
-5
votes
1answer
62 views

How to write SQL in a industry standard style [closed]

Here are the commands I ran to start setting up a database I need. ...
1
vote
2answers
92 views

Converting a String to USD

I'm working on a clientside iOS app for my school that involves students purchasing things, and I wrote a String extension for formatting a ...
2
votes
2answers
55 views

Method that receives a hexadecimal string and returns a formatted matrix of those values

This method is part of a larger project and comes after encoding ascii characters into hexadecimal values, so it assumes the parameter is always a valid hex string. ...
4
votes
2answers
117 views

Templated string formatting

This function formats a string by replacing every occurrence of '{n}' with the corresponding argument that was passed to the function where n is an index that ...
10
votes
2answers
124 views

Prettifier isn't pretty

Some context I'm implementing a self-closing pairs auto-completion feature in Rubberduck. One of the challenges is that the VBIDE API doesn't allow editing a line of code by "injecting" characters: ...
3
votes
1answer
69 views
3
votes
0answers
207 views

Pretty print a tree

When you're working with trees one of the most useful methods to implement is a clear way to print them, the following is my solution to print a tree in Java: ...
7
votes
1answer
154 views

Python tool to assemble CodeReview posts from source files

I hate having to format questions around here. Adding four spaces to each source file and the correct name at the top of each source file becomes a headache when I have to post longer questions. This ...
4
votes
1answer
53 views

Format seconds into the two biggest units of time

I wrote a function to convert seconds into the two biggest units of time and format it into a string. What I mean is that e.g. 134 second would be 02m14s and 3665 ...
2
votes
1answer
116 views

Printing 64-bit decimal numbers in freestanding environment

I need to print signed 64-bit numbers in decimal form. Program runs in freestanding environment (no C library available, libgcc may be unavailable too, or may not work correctly). So I can't use ...
2
votes
0answers
50 views

VIm function that runs file through shfmt

I've written a Vim function that formats the file using shfmt. I'd like to know if there is a way I can improve this script. I am bothered by the fact that I can't think of a way to do this without ...
4
votes
2answers
121 views

Show all primes in go

I'm trying to go through Adrian simple programming tasks; Elementary task 8 It's basically asking for an infinite loop to print every prime number as it finds it. Are there too many ...
5
votes
3answers
120 views

Displaying the date in MM/DD/YY format

I spent about an hour and a half attempting to complete a problem from W3Resource. Here is what I came up with, which works. How can I shorten it? ...
6
votes
2answers
383 views

Small Formatting Library

I am learning C++ and currently playing with variadic template functions and formatting string, So here is my small attempt to write a formatting function and provide a simple iostream-like interface ...
12
votes
5answers
3k 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 ...
2
votes
1answer
61 views

Fitter Nearest-Neighbor function with three nested loops

Background Problem Consider a set of students that we want to place into Ng groups each of which contains Ns students. Let's ...
2
votes
1answer
45 views

Finding a swimmer's competing position from a website

This is a code that allows a swimmer to know his position with respect to other competitors. It gets the swimmer's time from the meet's website, finds other competitors' times and shows the better ...
1
vote
2answers
72 views

Convert minute to time for display

I am new to javaScript, I just coded a method where I can convert a minute to a time in hh:mm AP/PM. I was then displaying the time in a table. I was wondering if there is a better approach to this? ...
5
votes
2answers
150 views

Bare-Bones implementation of printf

I made a bare-bones implementation of printf based on an exercise in Chapter 7, problem 5 of "Pointers on C" by Kenneth A. Reek. What criticism do you have of my ...
-2
votes
3answers
76 views

Formatting property for display [closed]

I am storing item's price in database as int. Now, I want to display that data in my a app s it were double. I found 2 ways to do this: ...
22
votes
4answers
655 views

Formatting 3 integers (hours, mins, secs) to `00:00:00`?

I have this at the moment, wondering if there's a cleaner way to do it or if this is already as compact as it gets. ...
5
votes
1answer
66 views

Pretty print uptime given seconds and omit unnecessary strings

Given an integer number of seconds, return a string which represents in human readable format the number of days/hours/minutes/seconds that are equivalent. ...