string-concatenation

Any reason not to use '+' to concatenate two strings?

北战南征 提交于 2019-11-26 12:16:10
问题 A common antipattern in Python is to concatenate a sequence of strings using + in a loop. This is bad because the Python interpreter has to create a new string object for each iteration, and it ends up taking quadratic time. (Recent versions of CPython can apparently optimize this in some cases, but other implementations can\'t, so programmers are discouraged from relying on this.) \'\'.join is the right way to do this. However, I\'ve heard it said (including here on Stack Overflow) that you

Android TextView : “Do not concatenate text displayed with setText”

笑着哭i 提交于 2019-11-26 11:47:45
问题 I am setting text using setText() by following way. prodNameView.setText(\"\" + name); prodOriginalPriceView.setText(\"\" + String.format(getString(R.string.string_product_rate_with_ruppe_sign), \"\" + new BigDecimal(price).setScale(2, RoundingMode.UP))); In that First one is simple use and Second one is setting text with formatting text. Android Studio is so much interesting, I used Menu Analyze -> Code Cleanup and i got suggestion on above two lines like. Do not concatenate text displayed

How to concatenate a String in EL?

徘徊边缘 提交于 2019-11-26 11:25:00
How do I get the promoPrice variable to print as part of the string ONLY $4.67 ? <c:set var="promoPrice" value="4.67" /> <p>${(promoPrice != null) ? "ONLY $${promoPrice}" : "FREE"}</p> If you're already on EL 3.0 (Java EE 7; WildFly, Tomcat 8, GlassFish 4, etc), then you could use the new += operator for this: <p>${not empty promoPrice ? 'ONLY $' += promoPrice : 'FREE'}</p> If you're however not on EL 3.0 yet, then use EL 2.2 (Java EE 7; JBoss AS 6/7, Tomcat 7, GlassFish 3, etc) capability of invoking direct methods with arguments, which you then apply on String#concat() : <p>${not empty

How to split string preserving whole words?

时光总嘲笑我的痴心妄想 提交于 2019-11-26 11:22:10
问题 I need to split long sentence into parts preserving whole words. Each part should have given maximum number of characters (including space, dots etc.). For example: int partLenght = 35; string sentence = \"Silver badges are awarded for longer term goals. Silver badges are uncommon.\" Output: 1 part: \"Silver badges are awarded for\" 2 part: \"longer term goals. Silver badges are\" 3 part: \"uncommon.\" 回答1: Try this: static void Main(string[] args) { int partLength = 35; string sentence =

Concat groups in SQL Server [duplicate]

五迷三道 提交于 2019-11-26 10:35:49
This question already has an answer here: How to use GROUP BY to concatenate strings in SQL Server? 16 answers If I have a table like this: +------------+ | Id | Value | +------------+ | 1 | 'A' | |------------| | 1 | 'B' | |------------| | 2 | 'C' | +------------+ How can I get a resultset like this: +------------+ | Id | Value | +------------+ | 1 | 'AB' | |------------| | 2 | 'C' | +------------+ I know this is really easy to do in MySQL using GROUP_CONCAT, but I need to be able to do it in MSSQL 2005 Thanks (Duplicate of How to use GROUP BY to concatenate strings in SQL Server? ) Pent

Adding quotes to a string in VBScript

狂风中的少年 提交于 2019-11-26 10:34:34
I have this code: a = "xyz" g = "abcd " & a After running it, the value of g is abcd xyz . However, I want quotes around the value of a in g . After running the code, g should be abcd "xyz" instead. How can I accomplish this? You can escape by doubling the quotes g="abcd """ & a & """" or write an explicit chr() call g="abcd " & chr(34) & a & chr(34) You have to use double double quotes to escape the double quotes (lol): g = "abcd """ & a & """" I usually do this: Const Q = """" Dim a, g a = "xyz" g = "abcd " & Q & a & Q If you need to wrap strings in quotes more often in your code and find

How to concatenate int values in java?

半腔热情 提交于 2019-11-26 10:32:41
I have the following values: int a=1; int b=0; int c=2; int d=2; int e=1; How do i concatenate these values so that i end up with a String that is 10221 ; please note that multiplying a by 10000, b by 1000.....and e by 1 will not working since b=0 and therefore i will lose it when i add the values up. The easiest (but somewhat dirty) way: String result = "" + a + b + c + d + e Edit: I don't recommend this and agree with Jon's comment. Adding those extra empty strings is probably the best compromise between shortness and clarity. Michael Borgwardt's solution is the best for 5 digits, but if you

String concatenation vs. string substitution in Python

让人想犯罪 __ 提交于 2019-11-26 10:09:56
问题 In Python, the where and when of using string concatenation versus string substitution eludes me. As the string concatenation has seen large boosts in performance, is this (becoming more) a stylistic decision rather than a practical one? For a concrete example, how should one handle construction of flexible URIs: DOMAIN = \'http://stackoverflow.com\' QUESTIONS = \'/questions\' def so_question_uri_sub(q_num): return \"%s%s/%d\" % (DOMAIN, QUESTIONS, q_num) def so_question_uri_cat(q_num):

java string concatenation and interning

给你一囗甜甜゛ 提交于 2019-11-26 09:59:21
问题 Question 1 String a1 = \"I Love\" + \" Java\"; String a2 = \"I Love \" + \"Java\"; System.out.println( a1 == a2 ); // true String b1 = \"I Love\"; b1 += \" Java\"; String b2 = \"I Love \"; b2 += \"Java\"; System.out.println( b1 == b2 ); // false In the first case, I understand that it is a concatenation of two string literals, so the result \"I Love Java\" will be interned, giving the result true. However, I\'m not sure about the second case. Question 2 String a1 = \"I Love\" + \" Java\"; //

XPath to return string concatenation of qualifying child node values

只愿长相守 提交于 2019-11-26 09:45:00
问题 Can anyone please suggest an XPath expression format that returns a string value containing the concatenated values of certain qualifying child nodes of an element, but ignoring others: <div> This text node should be returned. <em>And the value of this element.</em> And this. <p>But this paragraph element should be ignored.</p> </div> The returned value should be a single string: This text node should be returned. And the value of this element. And this. Is this possible in a single XPath