string-concatenation

+ operator for String in Java [duplicate]

爱⌒轻易说出口 提交于 2019-11-28 12:15:08
This question already has an answer here: How does the String class override the + operator? 7 answers I saw this question a few minutes ago, and decided to take a look in the java String class to check if there was some overloading for the + operator. I couldn't find anything, but I know I can do this String ab = "ab"; String cd = "cd"; String both = ab + cd; //both = "abcd" Where's that implemented? From the Fine Manual : The Java language provides special support for the string concatenation operator ( + ), and for conversion of other objects to strings. String concatenation is implemented

Can MySQL concatenate strings with ||

两盒软妹~` 提交于 2019-11-28 12:05:43
I'm using sqlite3 for the moment, and hence concatenation strings using the || operator. At some later date I'd like to shift to MySQL, and hence it would be nice if no changes to the code had to be made. I'd normally use concat() to concatenate in MySQL. Does || work too, or will I have to modify my code? Or is there any other solution? I'm coding in Ruby on Rails 3.1, by the way. codaddict The || works in MySQL as well but you need to set sql_mode to PIPES_AS_CONCAT . Official Doc Demo: mysql> select c from tmp; +------+ | c | +------+ | foo | | bar | +------+ 2 rows in set (0.00 sec) mysql>

Format specifier for integer variables in format() for EXECUTE?

ぃ、小莉子 提交于 2019-11-28 11:26:08
CREATE OR REPLACE FUNCTION getParentLtree(parent_id bigint, tbl_name varchar) RETURNS ltree AS $BODY$ DECLARE parent_ltree ltree; BEGIN -- This works fine: -- select into parent_ltree l_tree from tbl1 where id = parent_id; EXECUTE format('select into parent_ltree l_tree from %I where id = %I', tbl_name,parent_id); RETURN parent_ltree; END; $BODY$ LANGUAGE plpgsql; There are 2 issues in above function: parent_id is integer but it is replaced with quotes? What is the correct format specifier for int variables? select into does not work with EXECUTE ? How can I make above commented query to use

how to use concatenate a fixed string and a variable in Python

人走茶凉 提交于 2019-11-28 08:58:10
I want to include file name 'main.txt' in the subject for that I am passing file name from command line. but getting error in doing so python sample.py main.txt #running python with argument msg['Subject'] = "Auto Hella Restart Report "sys.argv[1] #line where i am using that passed argument I'm guessing that you meant to do this: msg['Subject'] = "Auto Hella Restart Report " + sys.argv[1] # To concatenate strings in python, use ^ Try: msg['Subject'] = "Auto Hella Restart Report " + sys.argv[1] The + operator is overridden in python to concatenate strings. Anto If you need to add two strings

Create comma separated strings C#?

我的梦境 提交于 2019-11-28 08:52:24
I have an object which holds many values, some of them (not all values from the object) need to be put in a csv string. My approach was this: string csvString = o.number + "," + o.id + "," + o.whatever .... Somehow I think there is a better, more elegant way? If you put all your values in an array, at least you can use string.Join . string[] myValues = new string[] { ... }; string csvString = string.Join(",", myValues); You can also use the overload of string.Join that takes params string as the second parameter like this: string csvString = string.Join(",", value1, value2, value3, ...);

PHP string concatenation using “,”?

柔情痞子 提交于 2019-11-28 08:34:06
问题 I just discovered something. echo $var1 , " and " , $var2; is the same as: echo $var1 . " and " . $var2; What is the actual string concatenation operator in php? Should I be using . or , ? 回答1: The . operator is the concatenation operator. Your first example only works because the echo 'function' (technically it's a language construct, but lets not split hairs) accepts more than one parameter, and will print each one. So your first example is calling echo with more than one parameter, and

Concatenate many rows into a single text string with grouping [duplicate]

放肆的年华 提交于 2019-11-28 07:39:50
This question already has an answer here: Can I Comma Delimit Multiple Rows Into One Column? [duplicate] 5 answers I have the following table: tblFile My Desired output: I am Concatenating many rows into a single text string; however, I cannot get the grouping correct. As the code is now it will just display for each record in the FileNameString field: AAA,BBB,CCC,DDD,EEE,FFF Any suggestions with the grouping! SELECT FileID, Stuff( (SELECT N', ' + CONVERT(Varchar, FileName) FROM tblFile FOR XML PATH(''),TYPE ) .value('text()[1]','nvarchar(max)'),1,2,N'')AS FileNameString From tblFile GROUP BY

Is string concatenaion really that slow?

女生的网名这么多〃 提交于 2019-11-28 07:31:41
I'm currently looking into String concat options and the penalty they have on the overall performance. And my test-case creates results that blow my mind, I'm not sure if I'm overlooking something. Here is the deal: Doing "something"+"somethingElse" in java will (at compile-time) create a new StringBuilder every time this is done. For my test-case, I'm loading a file from my HDD that has 1661 lines of example data (classic "Lorem Ipsum"). This question is not about the I/O performance , but about the performance of the different string concat methods. public class InefficientStringConcat {

Concatenation of LPWSTR strings

最后都变了- 提交于 2019-11-28 07:17:51
问题 In Visual C++, I have a LPWSTR mystring; which is already defined somewhere else in the code. I want to create a new LPWSTR containing: "hello " + mystring + " blablabla" (i.e. a concatenation) I'm getting mad with such a simple thing (concatenation)! Thanks a lot in advance, I'm lost! 回答1: The C++ way: std::wstring mywstring(mystring); std::wstring concatted_stdstr = L"hello " + mywstring + L" blah"; LPCWSTR concatted = concatted_stdstr.c_str(); 回答2: You can use StringCchCatW function 来源:

Evaluate preprocessor token before ## concatenation

北城以北 提交于 2019-11-28 07:17:50
问题 I would like to evaluate a token before it is concatenated with something else. The "problem" is that the standard specifies the behaviour as before the replacement list is reexamined for more macro names to replace, each instance of a ## preprocessing token in the replacement list (not from an argument) is deleted and the preceding preprocessing token is concatenated with the following preprocessing token. hence in the following example, #include <stdlib.h> struct xy { int x; int y; };