Google Apps Script date format issue (Utilities.formatDate)

The Utilities.formatDate() utility formats a javascript String. However, when written out to the spreadsheet, the new row of data is interpreted by Google Sheets to determine data types and appropriate formatting, just as if you’d typed it in through the user interface. Since you’ve got a recognizable date string, Google Sheets decides it’s a Date, … Read more

How do I escape curly-brace ({}) characters in a string while using .format (or an f-string)?

You need to double the {{ and }}: >>> x = ” {{ Hello }} {0} ” >>> print(x.format(42)) ‘ { Hello } 42 ‘ Here’s the relevant part of the Python documentation for format string syntax: Format strings contain “replacement fields” surrounded by curly braces {}. Anything that is not contained in braces is … Read more

PHP “pretty print” HTML (not Tidy)

you’re right, there seems to be no indentation for HTML (others are also confused). XML works, even with loaded code. <?php function tidyHTML($buffer) { // load our document into a DOM object $dom = new DOMDocument(); // we want nice output $dom->preserveWhiteSpace = false; $dom->loadHTML($buffer); $dom->formatOutput = true; return($dom->saveHTML()); } // start output buffering, using … Read more

How can I format a list to print each element on a separate line in python? [duplicate]

Embrace the future! Just to be complete, you can also do this the Python 3k way by using the print function: from __future__ import print_function # Py 2.6+; In Py 3k not needed mylist = [’10’, 12, ’14’] # Note that 12 is an int print(*mylist,sep=’\n’) Prints: 10 12 14 Eventually, print as Python statement … Read more

printf string, variable length item

There is no need to construct a special format string. printf allows you to specify the precision using a parameter (that precedes the value) if you use a .* as the precision in the format tag. For example: printf (“%d %.*s”, number, SIZE, letters); Note: there is a distinction between width (which is a minimum … Read more

How to create variable argument methods in Objective-C

What these are called, generally, is “variadic functions” (or methods, as it were). To create this, simply end your method declartion with , …, as in – (void)logMessage:(NSString *)message, …; At this point you probably want to wrap it in a printf-like function, as implementing one of those from scratch is trying, at best. – … Read more

Parse C# string to DateTime

Absolutely. Guessing the format from your string, you can use ParseExact string format = “ddMMyyyyHHmm”; DateTime dt = DateTime.ParseExact(value, format, CultureInfo.InvariantCulture); or TryParseExact: DateTime dt; bool success = DateTime.TryParseExact(value, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out dt); The latter call will simply return false on parse failure, instead of throwing an exception – if you may have bad … Read more

Formatting a double to two decimal places

string.Format will not change the original value, but it will return a formatted string. For example: Console.WriteLine(“Earnings this week: {0:0.00}”, answer); Note: Console.WriteLine allows inline string formatting. The above is equivalent to: Console.WriteLine(“Earnings this week: ” + string.Format(“{0:0.00}”, answer));

tech