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
4
votes
2answers
2k views

Printing a diamond-shaped figure

How can I optimize this code to have fewer loops and return values for unit testing? ...
1
vote
1answer
2k views

Format A TimeSpan With Years

I have a class with 2 date properties: FirstDay and LastDay. LastDay is nullable. I would ...
1
vote
1answer
400 views

Haskell MultiWayIf extension: When is it considered useful syntactic sugar? [closed]

The new MultiWayIf extension (available with GHC 7.6) allows guard syntax in an if: ...
7
votes
4answers
1k views

Printing all binary strings of length n

I have completed my homework with directions as follows: Declare and implement a class named Binary. This class will have a method named printB(int n) that prints all binary strings of length n. ...
6
votes
5answers
14k views

Displaying a person's personal information with formatting

I am learning C# from a book, and there is an exercise as follows: Write a program that has a person enter full name, age, and phone number. Display this information with formatting. Also display ...
5
votes
1answer
6k views

Underscore-case version of ActiveRecord model's name

Is there a better way to get the underscore-case version of an ActiveRecord model's name? So far this works, but it's far from ideal: ...
5
votes
1answer
450 views

Thoughts on organizing code for multiple mysql queries in php scripts

I have a web application where I connect with a MySQL database using PDO and in some scripts there are a lot of queries one after the other which don't necessarily concern the same tables. i.e I will ...
4
votes
1answer
6k views

Stripping formatting from text - Am I using an efficient jQuery selector?

I'm making a comment box using a contenteditable div, but I want to remove formatting from text a user might copy/paste into it (also no CTRL+B or CTRL+I shortcuts allowed either). Only "approved" ...
4
votes
2answers
3k views

Print character + the ASCII value, 10 pairs per line

My exercise was: Write a program that reads input as a stream of characters until encountering EOF. Have the program print each input character and its ASCII decimal value. Note that characters ...
1
vote
1answer
1k views

Getting a valid datetime format from a string

I have this code in a class that gets a string, parses it, and makes some adjustments to get a valid datetime format from the string. An input string for this ...
8
votes
1answer
1k views

Formatting a number

I'm writing out two numbers separated with a dash. The first number is padded with leading zeros until 6 digits, the second number, 4. ...
0
votes
2answers
309 views

Making a list human-readable

How is this function? ...
4
votes
4answers
624 views

How would I format this JavaScript code so it's more readable

How can I format this code so it's more readable? ...
36
votes
7answers
94k views

Setting a default value if a variable is empty

This is the pattern I've been using for "if the variable is empty, set a default value", and for variables like $muffin, it has all seemed well and good. But in ...
1
vote
6answers
486 views

Calling a FormatCurrency function on multiple textboses

I have a function called FormatCurrency() which I would like to call on each of the following elements: ...
4
votes
1answer
108 views

Liveupdate phone number forms and test for international numbers

I took a base from here and built on it. You call the function with onkeypress (hence live changing). The function gives output like this for domestic numbers: (...
3
votes
2answers
332 views

Formatting rows based on priority

I'd like to improve the readability of the following code. The aim of this code is to apply formatting to row(s) in a WinForms DataGridView based on the Priority of ...
8
votes
1answer
294 views

Computing a Discrete Cosine Transform matrix

I'm learning Haskell and I needed to work with discrete cosine transform matrices, so I made a program that generates text (usable in WolframAlpha) containing the generated matrix. The elements of ...
4
votes
2answers
68k views

Formatting a datetime string in the YYYYMMDD format

I'm working with some strange APIs that requires the dates to be sent in the YYYYMMDD format. I was thinking of doing something like this: ...
1
vote
1answer
4k views

String format function

string Format(string format_string, T1 p1, T2 p2, ..., TN pn) The Format() function takes a copy of ...
3
votes
1answer
146 views

Passing many configuration options to Java code formatter

I use the DefaultCodeFormatter of the core Java package to prettify my code. Unfortunately I want to look my code very different from the default settings. That why, I have to explicitly define a lot ...
8
votes
4answers
901 views

Zero-padding a number to have six digits

This is a switch statement in JavaScript. I have a feeling that it can be done in a shorter way. ...
6
votes
6answers
6k views

Best practice and alternatives for string manipulation with an emphasis on readability [closed]

As a personal habit I generally prefer to use string replace and format methods, along with string "patterns", in lieu of string ...
5
votes
4answers
1k views

Persist data by serializing/deserializing objects that are sent to it

I've created the following class to persist data by serializing/deserializing objects that are sent to it. I would like to know if there is a better way of writing this class, or if my class is fine ...
12
votes
3answers
2k views

My own C++ Format function

I've never been satisfied with any of the possible sprintf()-like functions in C++: sprintf() is a C function and it's very ...
5
votes
3answers
567 views

Formatting a possibly nil value as hours and minutes

This might be a bit silly because there are like a thousand ways to do this, but I'm struggling to come up with one that I like. I feel like this should fit in one line, but I don't like re-using ...
0
votes
1answer
771 views

Formatting some data about some airlines [closed]

...
11
votes
1answer
654 views

String interpolation library

I was bored over the last couple of days and wrote up a string interpolation library for JavaScript. I'm very pleased with its functionality, it passes it 79 tests cross browser and the comments and ...
27
votes
6answers
2k views

Formatter class

In our production code, we cannot use Boost or C++0x. Formatting strings using sprintf or stringstream is annoying in this case,...

1
7 8 9 10
11