string-concatenation

How can two strings be concatenated?

帅比萌擦擦* 提交于 2019-11-26 00:27:14
问题 How can I concatenate (merge, combine) two values? For example I have: tmp = cbind(\"GAD\", \"AB\") tmp # [,1] [,2] # [1,] \"GAD\" \"AB\" My goal is to concatenate the two values in \"tmp\" to one string: tmp_new = \"GAD,AB\" Which function can do this for me? 回答1: paste() is the way to go. As the previous posters pointed out, paste can do two things: concatenate values into one "string", e.g. > paste("Hello", "world", sep=" ") [1] "Hello world" where the argument sep specifies the character

Concatenating null strings in Java [duplicate]

≡放荡痞女 提交于 2019-11-25 23:54:56
问题 This question already has answers here : String concatenation with Null (3 answers) Closed 9 months ago . Why does the following work? I would expect a NullPointerException to be thrown. String s = null; s = s + \"hello\"; System.out.println(s); // prints \"nullhello\" 回答1: Why must it work? The JLS 5, Section 15.18.1.1 JLS 8 § 15.18.1 "String Concatenation Operator +", leading to JLS 8, § 5.1.11 "String Conversion", requires this operation to succeed without failure: ...Now only reference

How do I concatenate two strings in Java?

拥有回忆 提交于 2019-11-25 23:01:31
问题 I am trying to concatenate strings in Java. Why isn\'t this working? public class StackOverflowTest { public static void main(String args[]) { int theNumber = 42; System.out.println(\"Your number is \" . theNumber . \"!\"); } } 回答1: You can concatenate Strings using the + operator: System.out.println("Your number is " + theNumber + "!"); theNumber is implicitly converted to the String "42" . 回答2: The concatenation operator in java is + , not . Read this (including all subsections) before you

Shortcuts in Objective-C to concatenate NSStrings

本秂侑毒 提交于 2019-11-25 22:47:49
问题 Are there any shortcuts to ( stringByAppendingString: ) string concatenation in Objective-C, or shortcuts for working with NSString in general? For example, I\'d like to make: NSString *myString = @\"This\"; NSString *test = [myString stringByAppendingString:@\" is just a test\"]; something more like: string myString = \"This\"; string test = myString + \" is just a test\"; 回答1: Two answers I can think of... neither is particularly as pleasant as just having a concatenation operator. First,

nvarchar concatenation / index / nvarchar(max) inexplicable behavior

荒凉一梦 提交于 2019-11-25 22:45:25
问题 I today ran into a really weird problem in SQL Server (both 2008R2 and 2012). I\'m trying to build up a string using concatenation in combination with a select statement. I have found workarounds, but I would really like to understand what\'s going on here and why it doesn\'t give me my expected result. Can someone explain it to me? http://sqlfiddle.com/#!6/7438a/1 On request, also the code here: -- base table create table bla ( [id] int identity(1,1) primary key, [priority] int, [msg]

How to concatenate string variables in Bash

独自空忆成欢 提交于 2019-11-25 22:40:21
问题 In PHP, strings are concatenated together as follows: $foo = \"Hello\"; $foo .= \" World\"; Here, $foo becomes \"Hello World\". How is this accomplished in Bash? 回答1: foo="Hello" foo="${foo} World" echo "${foo}" > Hello World In general to concatenate two variables you can just write them one after another: a='Hello' b='World' c="${a} ${b}" echo "${c}" > Hello World 回答2: Bash also supports a += operator as shown in this code: $ A="X Y" $ A+=" Z" $ echo "$A" X Y Z 回答3: Bash first As this

How to create a SQL Server function to “join” multiple rows from a subquery into a single delimited field? [duplicate]

﹥>﹥吖頭↗ 提交于 2019-11-25 21:57:02
问题 This question already has answers here : How to concatenate text from multiple rows into a single text string in SQL server? (47 answers) Closed 2 years ago . To illustrate, assume that I have two tables as follows: VehicleID Name 1 Chuck 2 Larry LocationID VehicleID City 1 1 New York 2 1 Seattle 3 1 Vancouver 4 2 Los Angeles 5 2 Houston I want to write a query to return the following results: VehicleID Name Locations 1 Chuck New York, Seattle, Vancouver 2 Larry Los Angeles, Houston I know

How slow is Python's string concatenation vs. str.join?

随声附和 提交于 2019-11-25 21:42:29
As a result of the comments in my answer on this thread , I wanted to know what the speed difference is between the += operator and ''.join() So what is the speed comparison between the two? Dominic Bou-Samra From: Efficient String Concatenation Method 1: def method1(): out_str = '' for num in xrange(loop_count): out_str += 'num' return out_str Method 4: def method4(): str_list = [] for num in xrange(loop_count): str_list.append('num') return ''.join(str_list) Now I realise they are not strictly representative, and the 4th method appends to a list before iterating through and joining each item

How to use GROUP BY to concatenate strings in SQL Server?

你。 提交于 2019-11-25 21:38:19
问题 How do I get: id Name Value 1 A 4 1 B 8 2 C 9 to id Column 1 A:4, B:8 2 C:9 回答1: No CURSOR, WHILE loop, or User-Defined Function needed . Just need to be creative with FOR XML and PATH. [Note: This solution only works on SQL 2005 and later. Original question didn't specify the version in use.] CREATE TABLE #YourTable ([ID] INT, [Name] CHAR(1), [Value] INT) INSERT INTO #YourTable ([ID],[Name],[Value]) VALUES (1,'A',4) INSERT INTO #YourTable ([ID],[Name],[Value]) VALUES (1,'B',8) INSERT INTO

How to concatenate text from multiple rows into a single text string in SQL server?

假装没事ソ 提交于 2019-11-25 21:33:09
问题 Consider a database table holding names, with three rows: Peter Paul Mary Is there an easy way to turn this into a single string of Peter, Paul, Mary ? 回答1: If you are on SQL Server 2017 or Azure, see Mathieu Renda answer. I had a similar issue when I was trying to join two tables with one-to-many relationships. In SQL 2005 I found that XML PATH method can handle the concatenation of the rows very easily. If there is a table called STUDENTS SubjectID StudentName ---------- ------------- 1