Questions tagged [string-concatenation]

String concatenation is the operation of joining two character strings end-to-end.

In particular in the theory of computation, the concatenation operation on strings is generalized to an operation on sets of strings as follows:

For two sets of strings S1 and S2, the concatenation S1S2 consists of all strings of the form vw where v is a string from S1 and w is a string from S2. In this definition, the string vw is the ordinary concatenation of strings v and w as defined in the introductory section. In this context, sets of strings are often referred to as formal languages.

Programming languages often provide operators (such as the + sign) to simplify concatenation of strings. For example, "s1" + "s2" would result in "s1s2".

2012 questions
16
votes
4 answers

pyspark generate row hash of specific columns and add it as a new column

I am working with spark 2.2.0 and pyspark2. I have created a DataFrame df and now trying to add a new column "rowhash" that is the sha2 hash of specific columns in the DataFrame. For example, say that df has the columns: (column1, column2, ...,…
msashish
  • 277
  • 2
  • 6
  • 18
16
votes
4 answers

Concatenate inputs in string while in loop

I have a variable of sources that is basically a string of comma-separated elements: SOURCES="a b c d e" I want the user to input one destination for each of this source, and I want hence to store this input into a string looking like the above but…
Matteo NNZ
  • 11,930
  • 12
  • 52
  • 89
16
votes
3 answers

Concatenation of LPWSTR strings

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…
Basj
  • 41,386
  • 99
  • 383
  • 673
16
votes
3 answers

Performance: Java's String.format

Possible Duplicate: Should I use Java's String.format() if performance is important? I was wondering if is good to use String.format in Java apps instead of StringBuilder... so, I just write a simple test, like this: public static void…
caarlos0
  • 20,020
  • 27
  • 85
  • 160
15
votes
2 answers

T-SQL: issue with string concat

I have a set of audio files with names GreenLine1.mp3, GreenLine2.mp3 e.t.c. I'm going to write them into a table as BLOB (I use MS SQL Server'08), here's my sql request: DECLARE @aud AS VARBINARY(MAX) DECLARE @num AS INT -- Load the audio…
Ilya Blokh
  • 11,923
  • 11
  • 52
  • 84
15
votes
7 answers

lisp function to concatenate a list of strings

I need to write a function that will concatenate a list into a string. example: (concatString (quote ("hello" " world"))) ==> "hello world" here is what i have so far: (defun concatString (list) "A non-recursive function that concatenates a…
MBU
  • 4,998
  • 12
  • 59
  • 98
15
votes
1 answer

C# FormattableString concatenation for multiline interpolation

In C#7, I'm trying to use a multiline interpolated string for use with FormttableString.Invariant but string concatenation appears to be invalid for FormttableString. Per the documentation: A FormattableString instance may result from an…
Eugene
  • 10,957
  • 20
  • 69
  • 97
15
votes
7 answers

Is += more efficient than concat?

I've been reading code produced by other developers on my team, they seem to favor using += for String concatenation, whereas I prefer using .concat() as it feels easier to read. I'm trying to prepare an argument as to why using .concat() is better,…
Jimmy
  • 16,123
  • 39
  • 133
  • 213
15
votes
3 answers

Concatenate two char arrays?

If I have two char arrays like so: char one[200]; char two[200]; And I then want to make a third which concatenates these how could I do it? I have tried: char three[400]; strcpy(three, one); strcat(three, two); But this doesn't seem to work. It…
ingh.am
  • 25,981
  • 43
  • 130
  • 177
15
votes
2 answers

C# Compile-Time Concatenation For String Constants

Does C# do any compile-time optimization for constant string concatenation? If so, how must my code by written to take advantage of this? Example: How do these compare at run time? Console.WriteLine("ABC" + "DEF"); const string s1 =…
Joseph Sturtevant
  • 13,194
  • 12
  • 76
  • 90
15
votes
2 answers

nvarchar concatenation / index / nvarchar(max) inexplicable behavior

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…
14
votes
5 answers

String concatenation with ASP.NET MVC3 Razor

i'm trying to concatenate a string in asp.net mvc 3 razor and i'm getting a little sintax problem with my cshtml. i what to generate an id for my checkboxes on a foreach statement, and my checkboxes should start with "chk" and what to cancatenate a…
Flavio CF Oliveira
  • 5,235
  • 13
  • 40
  • 63
14
votes
10 answers

How to split string preserving whole words?

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…
jlp
  • 9,800
  • 16
  • 53
  • 74
14
votes
3 answers

Is it possible to concatenate heredoc string in PHP..?

With normal PHP string you can do this: $str = "Hello "; $str .= "world"; $str .= "bla bla bla"; $str .= "bla bla bla..."; But can you do the same with heredoc string..? $str = <<
pnichols
  • 2,198
  • 4
  • 24
  • 29
14
votes
8 answers

C#: most readable string concatenation. best practice

Possible Duplicate: How should I concatenate strings? There are several ways to concat strings in everyday tasks when performance is not important. result = a + ":" + b result = string.Concat(a, ":", c) result = string.Format("{0}:{1}", a,…
Andrew Florko
  • 7,672
  • 10
  • 60
  • 107