format

Replace all variables in Sprintf with same variable

两盒软妹~` 提交于 2019-12-28 16:47:06
问题 Is it possible using fmt.Sprintf() to replace all variables in the formatted string with the same value? Something like: val := "foo" s := fmt.Sprintf("%v in %v is %v", val) which would return "foo in foo is foo" 回答1: It's possible, but the format string must be modified, you must use explicit argument indicies: Explicit argument indexes: In Printf, Sprintf, and Fprintf, the default behavior is for each formatting verb to format successive arguments passed in the call. However, the notation

Formatting MAC address in C#

南楼画角 提交于 2019-12-28 06:30:08
问题 In my C# application, I want to get my MAC address by using NetworkInterface class as the following: NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces() { mac = nic.GetPhysicalAddress() } But this code returns the MAC without ':' or any other separator. How can I retrieve the MAC in this format: 88:88:88:88:87:88 using the code above ONLY? 回答1: try mac = string.Join (":", (from z in nic.GetPhysicalAddress().GetAddressBytes() select z.ToString ("X2")).ToArray()); 回答2: The help

Create a time interval of 15 minutes from minutely data in R?

限于喜欢 提交于 2019-12-28 05:54:11
问题 I have some data which is formatted in the following way: time count 00:00 17 00:01 62 00:02 41 So I have from 00:00 to 23:59hours and with a counter per minute. I'd like to group the data in intervals of 15 minutes such that: time count 00:00-00:15 148 00:16-00:30 284 I have tried to do it manually but this is exhausting so I am sure there has to be a function or sth to do it easily but I haven't figured out yet how to do it. I'd really appreciate some help!! Thank you very much! 回答1: For

SQL date format convert? [dd.mm.yy to YYYY-MM-DD]

半城伤御伤魂 提交于 2019-12-28 04:08:50
问题 is there mySQL function to convert a date from format dd.mm.yy to YYYY-MM-DD? for example, 03.09.13 -> 2013-09-03 . 回答1: Since your input is a string in the form 03.09.13 , I'll assume (since today is September 3, 2013) that it's dd.mm.yy . You can convert it to a date using STR_TO_DATE: STR_TO_DATE(myVal, '%d.%m.%y') Then you can format it back to a string using DATE_FORMAT: DATE_FORMAT(STR_TO_DATE(myVal, '%d.%m.%y'), '%Y-%m-%d') Note that the year is %y (lowercase "y") in STR_TO_DATE and %Y

Format a Google Sheets cell in plaintext via Apps Script

怎甘沉沦 提交于 2019-12-28 03:07:17
问题 Using Google Apps Script, I want to set the format for a Google Sheets cell to plain text. The reason I want to do this is because I want to show a date in the U.S. date format (MM/DD/YYYY). [We can assume the locale in the OP's Google account is set to use DD/MM/YYYY, a more common date format. –Ed.] I create the string like this: var thisDate = Utilities.formatDate (new Date (), SpreadsheetApp.getActiveSpreadsheet (). getSpreadsheetTimeZone (), "MM / d / yyyy"); ... which returns the date

Number format, writing 1e-5 instead of 0.00001

▼魔方 西西 提交于 2019-12-28 03:01:08
问题 I've used read.table to read a file that contains numbers such as 0.00001 when I write them back with write.table those numbers appear as 1e-5 How can I keep the old format? 回答1: You can do this by converting your numbers to strings with formatting as you require, then using the argument quote = FALSE in the call to write.table . dfr <- data.frame(x = 10^(0:15)) dfr$y <- format(dfr$x, scientific = FALSE) write.table(dfr, file = "test.txt", quote = FALSE) Note that you shouldn't need to change

How to get the given date string format(pattern) in java?

戏子无情 提交于 2019-12-28 02:01:37
问题 I want to get the format of a given date string. Example: I have a string like 2011-09-27T07:04:21.97-05:00 and the date format of this string is yyyy-MM-dd'T'HH:mm:ss.SSS . Here I want to find out this date format when I pass string( 2011-09-27T07:04:21.97-05:00 ) to a method which will return the format( yyyy-MM-dd'T'HH:mm:ss.SSS ), then later I will format my given date string according to my requirement( like yy-mm--dd or mm/dd/yyyy ). Can any one tell me how can I get it achieved? 回答1:

printf string, variable length item

≡放荡痞女 提交于 2019-12-27 17:30:28
问题 #define SIZE 9 int number=5; char letters[SIZE]; /* this wont be null-terminated */ ... char fmt_string[20]; sprintf(fmt_string, "%%d %%%ds", SIZE); /* fmt_string = "%d %9d"... or it should be */ printf(fmt_string, number, letters); Is there a better way to do this? 回答1: 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",

printf string, variable length item

谁说胖子不能爱 提交于 2019-12-27 17:30:26
问题 #define SIZE 9 int number=5; char letters[SIZE]; /* this wont be null-terminated */ ... char fmt_string[20]; sprintf(fmt_string, "%%d %%%ds", SIZE); /* fmt_string = "%d %9d"... or it should be */ printf(fmt_string, number, letters); Is there a better way to do this? 回答1: 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",

Add 'decimal-mark' thousands separators to a number

谁说我不能喝 提交于 2019-12-27 11:44:21
问题 How do I format 1000000 to 1.000.000 in Python? where the '.' is the decimal-mark thousands separator. 回答1: If you want to add a thousands separator, you can write: >>> '{0:,}'.format(1000000) '1,000,000' But it only works in Python 2.7 and higher. See format string syntax. In older versions, you can use locale.format(): >>> import locale >>> locale.setlocale(locale.LC_ALL, '') 'en_AU.utf8' >>> locale.format('%d', 1000000, 1) '1,000,000' the added benefit of using locale.format() is that it