format

JavaScript equivalent of Python's format() function?

夙愿已清 提交于 2019-12-17 22:34:16
问题 Python has this beautiful function to turn this: bar1 = 'foobar' bar2 = 'jumped' bar3 = 'dog' foo = 'The lazy ' + bar3 + ' ' + bar2 ' over the ' + bar1 # The lazy dog jumped over the foobar Into this: bar1 = 'foobar' bar2 = 'jumped' bar3 = 'dog' foo = 'The lazy {} {} over the {}'.format(bar3, bar2, bar1) # The lazy dog jumped over the foobar Does JavaScript have such a function? If not, how would I create one which follows the same syntax as Python's implementation? 回答1: Another approach,

Difference in event subscription formatting

对着背影说爱祢 提交于 2019-12-17 21:16:10
问题 Is there a difference between these two formats for subscribing to events: Style 1: foo.BarEvent += FooEventMethod; Style 2: foo.BarEvent += new FooEventHandler(FooEventMethod); 回答1: This is c# 1.0 style of subscribing an event. foo.BarEvent += new FooEventHandler(FooEventMethod); Starting from c# 2.0 you're allowed to subscribe event like this foo.BarEvent += FooEventMethod; above code is exactly equal to version1 code, what happens is compiler will create new FooEventHandler(FooEventMethod)

Converting PDF to image (with proper formatting)

﹥>﹥吖頭↗ 提交于 2019-12-17 20:38:59
问题 i have a pdf file(attached). My objective is to convert a pdf to an image using pdfbox AS IT IS,(same as using snipping tool in windows). The pdf has all kinds of shapes and text . i am using the following code: PDDocument doc = PDDocument.load("Hello World.pdf"); PDPage firstPage = (PDPage) doc.getDocumentCatalog().getAllPages().get(67); BufferedImage bufferedImage = firstPage.convertToImage(imageType,screenResolution); ImageIO.write(bufferedImage, "png",new File("out.png")); when i use the

What's the best way to format a phone number in Python?

一笑奈何 提交于 2019-12-17 20:04:04
问题 If all I have is a string of 10 or more digits, how can I format this as a phone number? Some trivial examples: 555-5555 555-555-5555 1-800-555-5555 I know those aren't the only ways to format them, and it's very likely I'll leave things out if I do it myself. Is there a python library or a standard way of formatting phone numbers? 回答1: for library: phonenumbers (pypi, source) Python version of Google's common library for parsing, formatting, storing and validating international phone numbers

JavaFX Table Cell Formatting

北慕城南 提交于 2019-12-17 19:21:21
问题 TableColumn<Event,Date> releaseTime = new TableColumn<>("Release Time"); releaseTime.setCellValueFactory( new PropertyValueFactory<Event,Date>("releaseTime") ); How can I change the format of releaseTime? At the moment it calls a simple toString on the Date object. 回答1: You can accomplish that through Cell Factories. See https://stackoverflow.com/a/10149050/682495 https://stackoverflow.com/a/10700642/682495 Although the 2nd link is about ListCell , the same logic is totally applicable to

Django: How to format a DateField's date representation?

廉价感情. 提交于 2019-12-17 18:17:51
问题 I have a form with a DateField. The existing date value is formatted to render like this: 2009-10-03 How can I format that so that it look like this: 03.10.2009 I found a widget which renders it like this, but validation doesn't allow the values I enter then. 回答1: To display initial field value properly formatted, use DateInput widget. To customize validation, use input_formats keyword argument of DateField. Why do you need both format and input_formats ? format - The format in which this

Parsing a Datetime String into a Django DateTimeField

对着背影说爱祢 提交于 2019-12-17 18:12:55
问题 I have a Django app with a model that contains a field of type DateTimeField. I am pulling data from the web in the format of 2008-04-10 11:47:58-05 . I believe that the last 3 characters in this example are the timezone. How can I preserve that data in the DateTimeField, and is there an easy conversion between the two? Setting the DateTimeField to simply contain a string of the above format throws a ValidationError. Thank you! 回答1: You can use import dateutil.parser dateutil.parser.parse(

Formatting RSA keys for OpenSSL in Java

淺唱寂寞╮ 提交于 2019-12-17 17:45:36
问题 Background RSA key generation with OpenSSL on Linux using the command, openssl genrsa -out mykey.pem 1024 created the following: "-----BEGIN RSA PRIVATE KEY----- MIICXQIBAAKBgQChs9Fepy5FgeL0gNJ8GHcKRHsYnM2Kkw19zwydDQNyh2hrHWV2 B11wpLFp8d0imcl2Wjb0oV/AxOhb3unQgNzs66LVuXJwS8icp3oIJZtExs6tkxzE s5mnU68wMeCYtJqHIZOmNblVWvpJMLNAwAVi3oLfnzDDbzjnDapm8M21nQIDAQAB AoGAZ11P1+acUHgvwMXcRtFIvvp5iYkqZouL00EYOghIjNx75gTbh7A7jbbpZeTi y6xsuMgAWy4QzGPSeG+tHMhS7+dYQNPuKSv5KtK3V7ubXz/I3ZN1etRVecA56QNw

How to display hexadecimal numbers in C?

北战南征 提交于 2019-12-17 17:29:07
问题 I have a list of numbers as below: 0, 16, 32, 48 ... I need to output those numbers in hexadecimal as: 0000,0010,0020,0030,0040 ... I have tried solution such as: printf("%.4x",a); // where a is an integer but the result that I got is: 0000, 0001, 0002, 0003, 0004 ... I think I'm close there. Can anybody help as I'm not so good at printf in C. Thanks. 回答1: Try: printf("%04x",a); 0 - Left-pads the number with zeroes (0) instead of spaces, where padding is specified. 4 (width) - Minimum number

Formatting scientific number representation in xsl

佐手、 提交于 2019-12-17 16:39:43
问题 I have the following value in my XML -1.8959581529998104E-4. I want to format this to the exact number it should be using XSL to give me -0.000189595815299981. format-number(-1.8959581529998104E-4,'0.000000;-0.000000') gives me NaN. Any ideas? Cheers Andez 回答1: XSLT 1.0 does not have support for scientific notation. This: number('-1.8959581529998104E-4') Result: NaN This: number('-0.000189595815299981') Result: -0.000189595815299981 XSLT 2.0 has support for scientific notation This: number('