string.format

Is CultureInfo.CurrentCulture really necessary in String.Format()?

流过昼夜 提交于 2019-12-09 04:33:48
问题 How do you think is really necessary to provide IFormatProvider in method String.Format(string, object) ? Is it better to write full variant String.Format(CultureInfo.CurrentCulture, "String is {0}", str); or just String.Format("String is {0}", str); ? 回答1: In general, you will want to use InvariantCulture if the string you are generating is to be persisted in a way that is independent of the current user's culture (e.g. in the registry, or in a file). You will want to use CurrentCulture for

Python - Using .format() string in a MySQL statement

时光怂恿深爱的人放手 提交于 2019-12-08 04:53:06
问题 I'm trying to format a mysql statement with today's data, as well as 7 days back. I'm pretty sure the date is in the correct format, so I don't think that's the issue. The error report is: Warning: (1292, "Incorrect datetime value: '{} 16:00:00' for column 'run_start_date' at row 1") result = self._query(query) Traceback (most recent call last): AttributeError: 'int' object has no attribute 'format' e.g. today = DT.date.today() week_ago = today - DT.timedelta(days=7) print(today.strftime('%Y-

Python - Using .format() string in a MySQL statement

谁说胖子不能爱 提交于 2019-12-07 22:29:26
I'm trying to format a mysql statement with today's data, as well as 7 days back. I'm pretty sure the date is in the correct format, so I don't think that's the issue. The error report is: Warning: (1292, "Incorrect datetime value: '{} 16:00:00' for column 'run_start_date' at row 1") result = self._query(query) Traceback (most recent call last): AttributeError: 'int' object has no attribute 'format' e.g. today = DT.date.today() week_ago = today - DT.timedelta(days=7) print(today.strftime('%Y-%m-%d')) print(week_ago.strftime('%Y-%m-%d')) cursor.execute(SELECT * FROM db WHERE run_start_date

Exception while using String.Format “Index (zero based) must be greater than or equal to zero and less than the size of the argument list.”

瘦欲@ 提交于 2019-12-07 16:24:29
I have an array ArrayList array = new ArrayList(); array.Add("a"); array.Add("b"); array.Add("c"); and I have a string variable refFormat which has the format as below. string refFormat = "{2} {0}"; I'm trying to get a string of values from the array with this format. Below is what I have written. string newStr = String.Format(refFormat,array.ToArray()); I'm getting the following exception when I'm trying to do this. Index (zero based) must be greater than or equal to zero and less than the size of the argument list. I know this question sounds repeated but my doubt is how to pick the values

Is there a more Pythonic way to pad a string to a variable length using string.format?

为君一笑 提交于 2019-12-07 12:24:40
问题 I want to pad a string to a certain length, depending on the value of a variable, and I'm wondering if there is a standard, Pythonic way to do this using the string.format mini-language. Right now, I can use string concatenation: padded_length = 5 print(("\n{:-<" + str((padded_length)) + "}").format("abc")) # Outputs "abc--" padded_length = 10 print(("\n{:-<" + str((padded_length)) + "}").format("abc")) #Outputs "abc-------" I tried this method: print(("{:-<{{padded_length}}}".format(padded

Using .NET string formatting, how do I format a string to display blank (empty string) for zero (0)?

僤鯓⒐⒋嵵緔 提交于 2019-12-07 02:28:45
问题 I am using a DataBinder.Eval expression in an ASP.NET Datagrid, but I think this question applies to String formatting in .NET in general. The customer has requested that if the value of a string is 0, it should not be displayed. I have the following hack to accomplish this: <%# IIf(DataBinder.Eval(Container.DataItem, "MSDWhole").Trim = "0", "", DataBinder.Eval(Container.DataItem, "MSDWhole", "{0:N0}")) %> I would like to change the {0:N0} formatting expression so that I can eliminate the IIf

Lua format.string can't format float as decimal (%d) as of 5.3

流过昼夜 提交于 2019-12-07 00:07:34
问题 I recently upgraded from Lua 5.2.3 to 5.3.1 but I noticed all my scripts that perform a string.format started failing if it tried to format a float using %d local anExampleString = string.format("Sample Number: %d",10.100000001) -- Fails on 5.3.1, works on 5.2.3 local aWorkingString = string.format("Sample Number: %.0f",10.100000001) -- Works on 5.3.1 Is this by design? I can't seem to find the change documented anywhere. 回答1: In Lua 5.3, the number type has two subtypes, integer and float .

How to get String.Format not to parse {0}

岁酱吖の 提交于 2019-12-06 07:59:09
I am writing a code generation tool that frequently will have lines like StringBuilder sp = new Stringbuilder(); sp.AppendFormat(" public {0}TextColumn()\n", className); sp.AppendLine(" {" sp.AppendLine(" Column = new DataGridViewTextBoxColumn();"); sp.AppendFormat(" Column.DataPropertyName = \"{0}\";\n", columnName); However the issue I am having is when I run in to a line like this. sp.AppendFormat("return String.Format(\"{0} = '{0}'\", cmbList.SelectedValue);", columnName); I want the first {0} to turn in to whatever the value of columnName is but I want the seccond {0} to be left alone so

Is there a more Pythonic way to pad a string to a variable length using string.format?

不想你离开。 提交于 2019-12-06 05:12:00
I want to pad a string to a certain length, depending on the value of a variable, and I'm wondering if there is a standard, Pythonic way to do this using the string.format mini-language . Right now, I can use string concatenation: padded_length = 5 print(("\n{:-<" + str((padded_length)) + "}").format("abc")) # Outputs "abc--" padded_length = 10 print(("\n{:-<" + str((padded_length)) + "}").format("abc")) #Outputs "abc-------" I tried this method: print(("{:-<{{padded_length}}}".format(padded_length = 10)).format("abc")) but it raises an IndexError: tuple index out of range exception: Traceback

coffeescript version of string.format, sprintf() etc. for javascript or node.js

本小妞迷上赌 提交于 2019-12-05 23:21:11
问题 How do I string.format() or sprintf() in coffeescript? 回答1: So there's 2 things going on here. First is interpolation, which coffeescript directly supports using double-quoted string literals and ruby style syntax like this: "The #{speed} #{color} #{animal} jumped over the lazy dog" That will replace the placeholders with the corresponding variables from the local scope. That's the idiomatic way to handle string interpolation in coffeescript (and ruby). Second is the formatting, which you