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
3
votes
2answers
691 views

Cleaning up an utterance using multiple regex substitutions

I need to use regex for some stuff (mentioned in code comments) and wrote the following code, which works perfectly fine for my need, but I wanted to know if there was a way to improve this code? Am ...
1
vote
1answer
289 views

Replace tabs with spaces

I wrote a program that replaces tabs with spaces. First, I defined a maximum length of an input string in the constant MAX_LIMIT. Next, I declared the procedure <...
1
vote
1answer
49 views

Add spaces around variable with $ symbol bookends

I have some code in a particular coding language, and I am trying to clean it up by adding spaces around the variables. I wrote this code, and it works on small amounts of text and if I set a break ...
3
votes
1answer
1k views

Using simple HTML template to create HTML formatting rules

One of my tools that renders HTML needs some rules about document formatting. The renderer can format the output so that it is indented and contains appropriate line-breaks. In the first version I ...
5
votes
2answers
897 views

Javascript wrap text with conditions

I have to wrap my text, when it's longer then 16 characters and when there is space " " or a dash "-". Can I write it with regex or a function that is easier to read than mine below? ...
5
votes
2answers
556 views

Formatting big integers as hexadecimal digits separated by colons

I'm pretty sure this can be written as a couple of lines, but I'm unable to come up with a better solution. ...
2
votes
1answer
371 views

Minify and send HTML response in Go

I need to have some static HTML pages on a project I am making with Go. I used the http.FileServer, but I noticed it was slower than rendering with ...
7
votes
3answers
955 views

String formatting for uint64_t that represents a fixed-point decimal

My goal is to take a uint64_t that represents a fixed-point decimal, and output a string representation of the decimal. The fixed-point representation always has ...
6
votes
1answer
1k views

HTML Tidy Sample Program in C++17

This is an exercise to use C++, Cevelop IDE & libtidy rather than the HTML Tidy command line tool. The program just reads from standarg input, processes the contents with HTML Tidy then puts the ...
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 ...
3
votes
2answers
362 views

Solution to itoa

As some of you might know I've been working my way through the C Programming Language (2nd). I recently finished a rough implementation of the itoa exercise (...
1
vote
0answers
68 views

MessageFormat in 2 Locales

I have an HTML template that contains a letter in two languages, EG German & English. I should fill in the same data in both languages. Excerpt from template: ...
1
vote
1answer
540 views

Converting Date object in CoffeeScript to string (with a weird format)

I'm trying to convert a Date object into a weird format, like so: 03/30/2017 11:37:14:082 -0500 The issue that really trips me up is the timezone offset. There's ...
2
votes
2answers
155 views

C program to convert a sum of money to Indian Number Format

I wanted to build a C program to convert any number to Indian Currency Format. It can take inputs with negative sign, leading zeros and Decimal point + Mantissa and it will format the input to take ...
3
votes
1answer
139 views

Indian currency format using C [closed]

Indian Currency format is 12345 → "12,345" (for odd length) and 123456 → "1,23,456" (for even length). I have included all ...
6
votes
2answers
2k views

Convert float price to integer price without commas

My payment gateway wants the prices this way: "1050" instead of 10.50. So I created this function: https://repl.it/HgHI/3 ...
6
votes
1answer
2k views

Text justification program

I'm looking for code review comments for text justification problem described here. Problem: Given an array of words and a length L, format the text such that each line has exactly L characters and ...
5
votes
3answers
75 views

Concatenating multiple feedback messages

The goal is to build a String from a given set where Feedback is an interface and ...
3
votes
3answers
6k views

Swift format string with separator every n characters where n changes

In Swift I have a string where a dash needs to be inserted after every 3 characters, if there are 4 characters or 2 characters at the end of the string they should be shown as "-xx-xx" or "-xx" ...
2
votes
4answers
103 views

Formatting a list with commas and occasional line breaks

I have an array mapped to make a typical result string separated by commas and with numbers a bit beautified with array.map(formatNumber). Expected format is <...
5
votes
1answer
9k views

Simple elapsed time counter

I've written a simple JavaScript function based off some existing code that takes a specific UNIX time string (in the snippet: 1491685200). It shows an alert if the ...
3
votes
1answer
401 views

regular expression for telephone/mobile per country and variable naming

would like to know if there is a better approach in doing a telephone/mobile number regular expression for specific country. this includes naming variables like how to know if format is international ...
2
votes
2answers
65 views

Manage input values from file according to number of elements per line

I was given the a test file with the following kind of content, an arbitrary number of integer pairs divided by a newline and a final line with one integer: ...
15
votes
5answers
4k views

Program to print a Python list as “a, b, and c”

I am a beginner (with zero Python experience) working through the book Automate the boring stuff with Python. At the end of Chapter 4, the author provides a review problem. I was supposed to write a ...
5
votes
1answer
2k views

Simple calendar in PHP

I made a simple calendar in PHP 7.0, could anyone help with simplification? Any advice appreciated. It works, but I totally believe it can be improved. I am a beginner. ...
-1
votes
1answer
426 views

Receipt printing tabulation [closed]

Currently I am working on a Receipt Printing Tabulation code in Java/Android. ...
4
votes
1answer
320 views

Ruby command-line app that outputs from JSON file

I made this application that runs fine, but I feel the code is sloppy as there are many if statements. I'm a beginner so I'm not sure how to improve it, at least not without messing everything up. Any ...
8
votes
1answer
582 views

Convert Iterable tree to string

I code this function to convert list of dict to a specific string to export last in a row table string field. ...
7
votes
4answers
318 views

Formatting date depending on current date

I have two screens where I show a message creation time and date. Initially, there was only one screen and I should always show time and show date differently depending on difference between today and ...
4
votes
2answers
1k views

Implementing console.table in JavaScript

I just wrote this simple function in order to implement something like console.table: ...
10
votes
3answers
20k views

Show time in format yyyy-MM-ddThh:mm:ss.SSS

My requirement is to convert a time (long) to a String with this date format: yyyy-MM-ddThh:mm:ss.SSS For instance: 2017-03-07T03:52:31.298 My implementation: ...
4
votes
1answer
500 views

Implementing printf to a string by calling vsnprintf twice

I'm experimenting with writing a dynamic string library in C, and I decided to write an implementation of sprintf. In my code, I call vsnprintf with a buffer of 0 ...
2
votes
2answers
176 views

Code minimizer - Remove unnecessary whitespace

I often do golf challenges, and thought it might be advantageous to write some code that automatically removes all the unnecessary whitespace from a program. After a few refactors, this is what I ...
10
votes
2answers
361 views

Python hash format converter

This program should convert a file containing Mana, Hashcat or John the Ripper NTLMv1 hashes to another file containing Hashcat or John the Ripper hashes. Do you have any suggestions on how to make ...
1
vote
0answers
212 views

Cookie Clicker esque game idea

I am making a cookie clicker type game as a small project, within Xcode, written in Swift. I have a been developing a function which will turn a Int64() into a 4 ...
4
votes
1answer
113 views

Path Finder Maze

The goal of my code was to find all possible moves from each open position in the maze (@moves_hash), assign it a value for how many moves it would take to get to ...
3
votes
4answers
224 views

JavaScript clock

I am trying to build a clock. You can see the working code here. However, I feel like I can do much better in the JavaScript code. ...
4
votes
1answer
130 views

Type for each value and naming, anonymous structs inside struct

Here is little snippet from my types.h code: ...
2
votes
3answers
87 views

Read and reformat a list of global variables output by a compiler

I'm currently going through a large Python program, with an eye to making it more readable and maintainable. Currently using Pylint and other code review tools throws a lot of unused variable warnings ...
5
votes
1answer
87 views

Format an Unsigned Byte to a Three ASCII Digits

I'm working on a game for the Atari VCS and have been dusting off my 30+ year old skills in writing MOS 6502 assembly language. The VCS runs at 1.19 MHz and is based on a MOS 6507 chip with some ...
5
votes
1answer
332 views

C program for whitespace normalization

I have made a beginner program using C that uses file handling and formats the given file. Formatting includes removing trailing blank spaces, replacing one or more blanks by a single blank and also ...
4
votes
3answers
4k views

Transforming tuple with (int month, int year) in string “mm/yyyy”

I would like to improve the following code: ...
4
votes
1answer
411 views

Print fragment of multiplication table

I am learning Python online on Stepik platform, and unfortunately I don't have any opportunity to get reviews from the tutor. The platform only checks the correctness of the answer that my program ...
1
vote
1answer
1k views

Generating a sequence number based on last item of a list

I wrote this method in order to generate a sequence number based on a specific pattern: ...
8
votes
2answers
168 views

entab program which replaces 4 spaces with a tab

I wrote an entab program which needs to replace every \$n\$ spaces with 1 tab. I picked \$n\$ to be 4, so every 4 spaces should be 1 tab. I have a feeling that my code is far too complicated than it ...
2
votes
1answer
467 views

JSON pretty print

Here is my simple program to pretty print a JSON object. I'm looking for advice of better pretty print solutions, functional bugs, code style and algorithm time/space complexity improvements. BTW, I ...
2
votes
2answers
9k views

time_t to string

...
12
votes
6answers
3k views

Format RGB Long as hex string in VB6

This is how I convert e.g. RGB(255, 0, 0) (where red is stored in the least significant byte of a Long) to a 6-digit hex string <...
7
votes
1answer
118 views

Converting a 12h clock to 24h clock

I started picking up Rust on my free time, and I'm curious about what style errors have I made and where should I improve as a programmer. The problem is from HackerRank and very simple: there is a ...
2
votes
1answer
10k views

Converting double to string without scientific notation and without losing digits

Requirements: Must convert a double to a string, without losing any digits. Cannot use scientific notation. In C#, no format ...

1
3 4
5
6 7
11