string-formatting

Which log4j facade to choose?

China☆狼群 提交于 2019-12-07 11:09:14
问题 Essentially I'm looking for something with the same behavior, configuration, logging levels as log4j, but with some of the missing functionality (e.g. formatted logging — see here and here for related SO threads.) Current nominees are slf4j and log5j. 回答1: I'm inclined toward SLF4J. allows parameterized logging (formatting) allows consolidation of other frameworks (great for apps using many libraries, each logging to a different framework) log5j is good, but does not have near as much market

String.Format in C# not returning modified int value

末鹿安然 提交于 2019-12-07 09:44:22
问题 I am tring to return an int value with comma seperators within the value. 12345 would be returned as 12,345 The follwing code works: int myInt = 1234567; MessageBox.Show(string.Format("My number is {0}", myInt.ToString("#,#"))); 12,345 is displayed as expected. While the following code does no work, but from what I am reading, should work: int myInt = 1234567; MessageBox.Show(string.Format("My number is {0:#,#}", myInt.ToString())); 12345 is displayed. Can you help me understand why the

scanf format to ignore irrelevant characters

走远了吗. 提交于 2019-12-07 08:39:07
问题 I wrote a short example code to illustrate my problem #include <stdio.h> #include <string.h> unsigned parseAndCompareDouble(const char* inSTR, const char* inF, const char * expect, const char * outF){ unsigned e = 0; char buffer[2000]; double a = 0; if( 1 != sscanf_s( inSTR, inF, &a, sizeof(double) ) ) e += 1; if( (int) strlen(expect) != sprintf_s(buffer, 2000, outF, a) ) e += 1; if( 0 != strcmp(expect, buffer) ) e += 1; return e; } unsigned main( void ) { unsigned e = 0; const char *

Custom string formatter in C#

孤者浪人 提交于 2019-12-07 07:57:13
问题 String formatting in C#; Can I use it? Yes. Can I implement custom formatting? No. I need to write something where I can pass a set of custom formatting options to string.Format , which will have some effect on the particular item. at the moment I have something like this: string.Format("{0}", item); but I want to be able to do things with that item: string.Format("{0:lcase}", item); // lowercases the item string.Format("{0:ucase}", item); // uppercases the item string.Format("{0:nospace}",

python string replacement with % character/**kwargs weirdness

≯℡__Kan透↙ 提交于 2019-12-07 06:34:58
问题 Following code: def __init__(self, url, **kwargs): for key in kwargs.keys(): url = url.replace('%%s%' % key, str(kwargs[key])) Throws the following exception: File "/home/wells/py-mlb/lib/fetcher.py", line 25, in __init__ url = url.replace('%%s%' % key, str(kwargs[key])) ValueError: incomplete format The string has a format like: http://www.blah.com?id=%PLAYER_ID% What am I doing wrong? 回答1: You probably want the format string %%%s%% instead of %%s% . Two consecutive % signs are interpreted

How to do string formatting with unicode emdash?

五迷三道 提交于 2019-12-07 05:51:13
问题 I am trying do string formatting with a unicode variable. For example: >>> x = u"Some text—with an emdash." >>> x u'Some text\u2014with an emdash.' >>> print(x) Some text—with an emdash. >>> s = "{}".format(x) Traceback (most recent call last): File "<stdin>", line 1, in <module> UnicodeEncodeError: 'ascii' codec can't encode character u'\u2014' in position 9: ordinal not in range(128) >>> t = "%s" %x >>> t u'Some text\u2014with an emdash.' >>> print(t) Some text—with an emdash. You can see

Formatting a nan float in python

泪湿孤枕 提交于 2019-12-07 05:02:25
问题 I'm trying to use string.format on a 'nan' float. Here's the description of the 'g' option from the python documentation. General format. This prints the number as a fixed-point number, unless the number is too large, in which case it switches to 'e' exponent notation. Infinity and NaN values are formatted as inf, -inf and nan, respectively. And here's what i get trying it in the interpreter (Python 2.6): >>> print "{0:g}".format(float('nan')) -1.#IND As I understand the documentation, the

PyCharm and f-strings

╄→гoц情女王★ 提交于 2019-12-07 04:38:18
问题 I am using the latest stable PyCharm 2016.1.4 and Python 3.6a1. Whenever I use the "f-strings" (PEP-498) PyCharm is complaining about f being an unresolved reference : Is the literal string interpolation not supported by PyCharm yet? Or, should I have enabled or configured it separately? 回答1: The Literal String Interpolation is now supported in PyCharm 2016.3, the relevant feature request: PY-18972 implement support for PEP 498 (f-strings) Note that the stable 3.6 is scheduled to be released

HTML formatting for TextView

£可爱£侵袭症+ 提交于 2019-12-07 04:32:38
问题 I am a bit confused about the 'rules' of when a TextView element displays text in formatted form or not. A string like "There are <i>different ways</i> of coding.\n"; displays without any formatting (including the HTML codes) when I code tvMyTextView.setText("There are <i>different ways</i> of coding.\n"); but when I define the same string in strings.xml and then load tvMyTextView.setText(R.strings.TestString); it displays emphasized. Even more confused I feel when trying to embed URLs in

IndexError: tuple index out of range when parsing method arguments

依然范特西╮ 提交于 2019-12-07 02:35:03
问题 I've already checked this question, but couldn't find an answer there. Here is a simple example that demonstrates my use case: def log(*args): message = str(args[0]) arguments = tuple(args[1:]) # message itself print(message) # arguments for str.format()0 print(arguments) # shows that arguments have correct indexes for index, value in enumerate(arguments): print("{}: {}".format(index, value)) # and amount of placeholders == amount of arguments print("Amount of placeholders: {}, Amount of