Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Questions tagged [formatting]

For programs that are concerned with producing 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. (Note that code layout is always in scope for answers, so this tag is not used to indicate perceived issues with that).

Filter by
Sorted by
Tagged with
3 votes
0 answers
12 views

LeetCode 68. Text Justification

I am trying out this Leetcode(Difficulty : Hard) Problem and I need your help to asses the code. I am pretty new to this. Given an array of strings words and a width maxWidth, format the text such ...
user avatar
0 votes
1 answer
21 views

Rust program to print citations in Chicago author-date style

I have written a Rust program that lets you input a citation's metadata in a Bibtex-like format and generates a bibliography entry formatted in Markdown that conforms (more or less) to the Chicago ...
user avatar
  • 195
0 votes
1 answer
30 views

Integer array to string

This function creates takes an int * buffer and creates a neatly formatted string (useful for printing the contents of an array). Is the code easy to follow? Is it ...
user avatar
  • 155
4 votes
1 answer
148 views

Parse floats to a custom numeric format string

I'm working to implement a custom string format. These are the float values to convert into a string: ...
user avatar
  • 43
3 votes
1 answer
278 views

Python function to output a string that is justified to the right

I just solved this exercise from Think Python, 2nd edition: Python provides a built-in function called len that returns the length of a string, so the value of len('allen') is 5. Write a function ...
user avatar
0 votes
1 answer
48 views

custom button class for android game engine

I'm a self-taught programmer and I haven't really followed industry-standard coding classes. I'm currently coding my own game engine for android, though and I was wondering if my coding style could ...
user avatar
  • 3
8 votes
1 answer
83 views

Converting a number to a string with a maximum of 3 numerals plus SI unit

I wrote a function that receives a number as an argument and returns a number (technically, a string) with a maximum of 3 numerals, no matter if there's a decimal separator or not, plus the adequate ...
user avatar
2 votes
1 answer
68 views

Encode non-negative integer to a string of ascii letters and digits

I want to encode a non-negative integer to ASCII letters and digits. I wrote below code for that, that works, but which I assume too immature to use in production. ...
user avatar
2 votes
4 answers
120 views

Formatted output of a phone number from an array of int

I wrote a function that takes an array of 10 integers (from 0 to 9) that returns a string of those numbers as a phone number. Example: ...
user avatar
3 votes
1 answer
227 views

Format an integer with space as thousand separator

I need to format a number with space as thousand separator in my Java code for Android. How can these functions be improved? What are the pros and cons to the first recursive method? What are the ...
user avatar
19 votes
4 answers
2k views

Minimal `printf` for integer types in x86 assembly

I'm writing a minimal C runtime targeting an old 32-bit Windows XP machine as a personal project. The C runtime provided by compilers is quite bloated. I wouldn't mind some library bloats up to ...
user avatar
  • 411
1 vote
2 answers
189 views

Create an ASCII table from CSV

The following code convert csv to ascii table. ...
user avatar
4 votes
0 answers
33 views

formatting flattened string into JSON-like object in C++, part 2

I have reworked the code from my previous (linked) post. For reference: I have a string which contains JSON-like object flattened (stringify()ed). I need to JSON-...
user avatar
2 votes
1 answer
73 views

formatting flattened string into JSON-like object in C++

I have a string which contains JSON-like object flattened (stringify()ed). I need to JSON-ify it back. It's a custom format, so I wrote function to JSON-ify the ...
user avatar
-2 votes
2 answers
126 views

Write conditional expression better [closed]

I have the following code function x () { return a ? (b ? 'result2' : 'result1') : 'result1'; } Is there a better way to combine these two conditions into one?...
user avatar
3 votes
2 answers
445 views

Simple string manipulation in C (for small microcontrollers)

Although I have long experience of other languages, I've not used C until playing around with microcontrollers using the Arduino IDE. I'm a bit uncomfortable with my use of pointers in conjunction ...
user avatar
0 votes
2 answers
97 views

Is there a neater, more elegant way to format this output?

I have this code that writes the initial configuration of a simulator I'm writing to stdout. args is an instance of type ...
user avatar
  • 103
2 votes
1 answer
84 views

Beginner Q: Is there a cleaner way to group a list in JS?

I'm looking to highlight some words on a webpage, I've grouped them now, but changed the css and html slightly and this seems to have broken it. For context, looking to add a list of words in JS which ...
user avatar
4 votes
1 answer
172 views

Gear Shift Indicator using Hall Effect Sensors & 8x8 LED Display

I wired up a Gear Shift Indicator for my dad's car to display what gear it is currently in, and showing changes with animations (sliding up and down as appropriate, with a few bonus ones for fun at ...
user avatar
1 vote
2 answers
49 views

Colour message prettifier in Bash

Features: messages formatted with clear borders errors sent to stderr colour handling colours can be included in other strings echoed to the screen without having ...
user avatar
  • 229
-1 votes
2 answers
176 views

DiscountManager class in C#

I built a class in C#, DiscountManager, which is responsible for calculating a customer discount based on years of loyalty. I want to refactor it and am seeking any ...
user avatar
3 votes
0 answers
75 views

Use formats phone numbers into XXX-XXX-XXX

I created an input that accepts and formats phone numbers into XXX-XXX-XXX. The user should be able to type numbers and the dashes should insert themselves automatically. Example #1: The user types 1 ...
user avatar
  • 131
-1 votes
1 answer
111 views

Better way to format a query string in Java

description I'm using influxDB, I need use Java to generate a query command. The TestingTag struct maybe missing 0-3 fields. code: ...
user avatar
7 votes
2 answers
264 views

Word wrap with file input & ouput

As this is a very basic word wrap program, it has at least the following 3 limitations :- The file should have a terminating newline. The column number at which the lines are to be wrapped must be ...
user avatar
6 votes
1 answer
351 views

Python function to print a two-column table from a dictionary

I'm currently learning Python for a masters and am trying to improve the best I can, as I'll need to know how to code in my future career. I currently have a function that builds a table from a ...
user avatar
4 votes
1 answer
74 views

How to make my code shorter. This Code formats Credit card number. Vanilla JS

How to make my script shorter and better? This code allows only digits, auto-format card number like this XXXX XXXX XXXX XXXX. if user hits delete or backspace to delete space in between digits, ...
user avatar
  • 41
1 vote
1 answer
202 views

Read and display JSON results from Google Books API

I’m working with the Google Books API and I’m not so sure about the way I’m going to get the search data and return it to the user. I will describe the path here and I would like to know if you would ...
user avatar
  • 369
0 votes
1 answer
49 views

Very unorthodox placement of if-else clauses in C for handling special cases [closed]

I've encountered a situation with an if-else clause. Specifically, the positive case has only 1 expression, whereas the negative case is a sequence of statements wrapped in braces. Like this: ...
user avatar
  • 278
2 votes
3 answers
126 views

HTML/JavaScript temperature converter with rounding

I am looking to improve the performance of my code through best practices and cleaner code. My goal here is just to perform a conversion whenever there is a keyup. But I noticed that my code looks ...
user avatar
  • 369
1 vote
1 answer
73 views

Car price calculator

Im writing this simple program for school and using NumberFormat on all the variables seems very repetitive (Note that we were asked to use the NumberFormat method)....
user avatar
4 votes
2 answers
281 views

Tic-tac-toe in python with OOP

I'm a beginner to intermediate in programming, and created a Tic-tac-toe game in python. I plan to add an AI player and a GUI using pygame. Any improvements I could make to the code, especially with ...
user avatar
  • 41
1 vote
0 answers
28 views

Powershell Refolder by Filename Before Delim

I'm pretty new to Powershell but have been using it more and more to automate tasks at work. Now I'm reaching out for some help. I typically use the scripts I write in a way where I copy and paste the ...
user avatar
1 vote
1 answer
30 views

Is there a cleaner/better way to write this Contact Manager in React?

I am learning React by doing a Contact Manager, I am trying to write this code more efficiently. Any ideas...good practise, component splitting, formatting tips are accepted too. Thanks in advance P.S....
user avatar
  • 13
0 votes
1 answer
111 views

Markdown table strings to two dimensional array converter implementation in C#

I am attempting to implement a converter which can convert List<string> type markdown table into two dimensional array ...
user avatar
  • 3,302
1 vote
0 answers
25 views

Does Oracle have a mistake in their documentation regarding switch case formatting? [closed]

Here is a reference to how switch statements should be formatted (I've never seen this used at the two companies I've worked at): And a contradictory one, which I am partial to (and is IntelliJ IDEA ...
user avatar
  • 131
2 votes
1 answer
342 views

Two Dimensional Array to Markdown Table Converter Implementation in C#

I am attempting to implement a converter which can convert two dimensional array (such as string[,]) into markdown table. The experimental implementation The ...
user avatar
  • 3,302
2 votes
3 answers
132 views

Convert string format python

I want to fix number of digits after '.' in digit represented by string. Is there better solution than mine? My code ...
user avatar
  • 125
0 votes
1 answer
136 views

JavaScript date format string to php date format string convert

Please find the following scenario, I've dynamic JS date format string from API but I am looking for the best way to convert the format that accepts in PHP date format. For now, I wrote it my own way ...
user avatar
  • 1
13 votes
3 answers
1k views

Logger module in C

I wrote a logger module in C, that is essentially a printf wrapper + some additional color coding: I'd like get feedback how I can improve performance and also use better coding style. Right now, I ...
user avatar
  • 795
8 votes
2 answers
352 views

Huffman encoding bitcodes display

So, the concept of the code is simple. Take any file, read the binary character counts and construct a Huffman tree, and then output the bit code of each character (displayed as its 8-bit value). This ...
user avatar
9 votes
2 answers
417 views

Comma formatted list printer

I'm working on a list practice project from the book "Automate the Boring Stuff with Python" which asks for this: Write a function that takes a list value as an argument and returns a ...
user avatar
  • 101
4 votes
1 answer
27 views

Creating formatted "[time] [unit] ago" messages from a seconds value

I have this function which calculates how many seconds, mins, hours etc ago a specific time string was. However, the way I have done it consists of a massive if statement block, and it goes through ...
user avatar
  • 141
10 votes
2 answers
306 views

Text based rendering/animation engine for the terminal

This project was highly inspired by the popular drawille project, that lets one draw to the terminal using the braille unicode characters. The advantage of drawing with braille characters compared to ...
user avatar
  • 795
5 votes
2 answers
345 views

Can it be shorter?: DNA Sequence Analyzer from CS50 written in Python

This is my first time requesting a code review. This is code I wrote in Python to create a DNA sequence analyzer. This is for the Harvard CS50 course. I was really hoping to get some constructive ...
user avatar
  • 61
4 votes
2 answers
113 views

Format string processing similar to date or printf()

I wrote a function that is supposed to take a format string similar to what date accepts and replace all format specifiers with strings provided by a callback ...
user avatar
  • 238
3 votes
1 answer
47 views

XML Tree Reformatter requested code. C#

So this is a post as per request in a different post on stack overflow: https://stackoverflow.com/questions/62412713/why-does-my-c-sharp-xml-code-only-work-when-i-enumerate-variable-enumerable. The ...
user avatar
  • 31
2 votes
1 answer
131 views

Command Line app for calculating payroll in Java

I had an assignment last semester to program a payroll app utilizing methods. I went back to it and re-wrote it to include an extra class as well. I would like some feedback regarding whether my code ...
user avatar
  • 41
7 votes
2 answers
105 views

Pretty-print dollar amounts using custom precision for large amounts

Given a floating-point number, which is representing a dollar value, I'm aiming to return a rounded, human-readable string. Here are the rules for numbers equal to or greater than 1 million, equal to ...
user avatar
5 votes
2 answers
511 views

Dynamic String Alignment Code

My code works for user output alignment to the right side by maximum length of 4 different user input. I have 2 question. Is there a simplier way for append method in my code ? Is there a simplier ...
user avatar
  • 137
6 votes
2 answers
464 views

Creating and listing a song collection

Songs Class: ...
user avatar

1
2 3 4 5
12