String.format() and hex numbers in Java

I’m trying to figure out why String.format() is behaving the way it does. Context: Systems programming class, writing an assembler. There is a 5 character hex field in the object file, which I am creating from a value. Tried using: String.format(“%05X”, decInt); This works as intended for positive numbers (11 -> 0000B) However it fails … Read more

Pad left or right with string.format (not padleft or padright) with arbitrary string

Can I use String.Format() to pad a certain string with arbitrary characters? Console.WriteLine(“->{0,18}<-“, “hello”); Console.WriteLine(“->{0,-18}<-“, “hello”); returns -> hello<- ->hello <- I now want the spaces to be an arbitrary character. The reason I cannot do it with padLeft or padRight is because I want to be able to construct the format string at a … Read more

When do you use StringBuilder.AppendLine/string.Format vs. StringBuilder.AppendFormat?

A recent question came up about using String.Format(). Part of my answer included a suggestion to use StringBuilder.AppendLine(string.Format(…)). Jon Skeet suggested this was a bad example and proposed using a combination of AppendLine and AppendFormat. It occurred to me I’ve never really settled myself into a “preferred” approach for using these methods. I think I … Read more

Python function argument list formatting

What is the best way to format following piece of code accordingly to PEP8: oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, token=token, verifier=verifier, http_url=ACCESS_TOKEN_URL) The problem is that if I place more than one parameter on the first line, the line exceeds 79 characters. If I place each of the parameters on a separate line with 4 spaces indentation … Read more

SQL formatting standards [closed]

Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year. Improve this question In my last job, we worked on a very database-heavy application, and I developed some formatting standards … Read more

How can I produce a human readable difference when subtracting two UNIX timestamps using Python?

This question is similar to this question about subtracting dates with Python, but not identical. I’m not dealing with strings, I have to figure out the difference between two epoch time stamps and produce the difference in a human readable format. For instance: 32 Seconds 17 Minutes 22.3 Hours 1.25 Days 3.5 Weeks 2 Months … Read more