string-concatenation

PHP string concatenation using “,”?

旧巷老猫 提交于 2019-11-29 14:32:59
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 , ? 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 they are all being printed, vs. the second example where all the strings are being concatentated and that one

Concatenation of LPWSTR strings

不问归期 提交于 2019-11-29 13:49:30
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! The C++ way: std::wstring mywstring(mystring); std::wstring concatted_stdstr = L"hello " + mywstring + L" blah"; LPCWSTR concatted = concatted_stdstr.c_str(); You can use StringCchCatW function 来源: https://stackoverflow.com/questions/15421139/concatenation-of-lpwstr-strings

T-SQL: issue with string concat

不打扰是莪最后的温柔 提交于 2019-11-29 13:18:26
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 data SET @num=1 WHILE (@num<38) BEGIN; SELECT @aud = CAST(bulkcolumn AS VARBINARY(MAX)) FROM OPENROWSET( BULK 'C:\Users\Ilya\folder\GreenLine' + CAST(@num AS VARCHAR) + '.mp3', SINGLE_BLOB ) AS x -- Insert the data to the table INSERT INTO Mb2.dbo.Audios (Id, [Content]) SELECT NEWID(), @aud SET @num = @num + 1 END; I have an error: Incorrect syntax near '+',

Concatenate multiple HTML text inputs with stored variable

守給你的承諾、 提交于 2019-11-29 12:47:42
I am trying to create a simple html form which asks for some details from a user and once this has been submitted will add the text to some predetermined text in a text box. Example of this... Text box 1 - Enter Name Text box 2 - Enter Age Text box 3 - Enter Location When this is submitted I would like this to be added preferably into a text box or even just output has text on an html page with other text already stored so the output would maybe be something like "Hello John, you are 25 years old and from London". What I have is very basic: <html> <form> Name: <input type="text" name="name">

why does a char + another char = a weird number

大兔子大兔子 提交于 2019-11-29 12:10:44
Here's the code snippet: public static void main (String[]arg) { char ca = 'a' ; char cb = 'b' ; System.out.println (ca + cb) ; } The output is: 195 Why is this the case? I would think that 'a' + 'b' would be either "ab" , "12" , or 3 . Whats going on here? polygenelubricants + of two char is arithmetic addition, not string concatenation. You have to do something like "" + ca + cb , or use String.valueOf and Character.toString methods to ensure that at least one of the operands of + is a String for the operator to be string concatenation. JLS 15.18 Additive Operators If the type of either

Why does + work with Strings in Java?

泄露秘密 提交于 2019-11-29 10:29:08
Java can't do operator overloading, but + works okay for String and Integer and some other classes. How is this possible? update: Why does this work? Integer i = 4; Integer p = 5; System.out.println(i*p); // prints 20 + is not an example of operator overloading. + is built into the language as a concatentation operator and an arithmetic-addition operator. What this means is that a person writing a program with Java cannot overload operators, but as far as the grammar of the Java language is concerned, + is defined as a concatenation and an addition operator. EDIT It works for other classes

Is it more Pythonic to use String Formatting over String Concatenation in Python 3?

青春壹個敷衍的年華 提交于 2019-11-29 08:54:24
So I'm programming a text game in Python 3.4 that requires the use of the print() function very often to display variables to the user. The two ways I've always done this is with string formatting and string concatenation : print('{} has {} health left.'.format(player, health)) And, print(player + ' has ' + str(health) + ' health left.') So which is better? They're both equally as readable and quick to type, and perform exactly the same. Which one is more Pythonic and why? Question asked as I couldn't find an answer for this on Stack Overflow that wasn't concerned with Java. Eddie Depends upon

String.Format vs “string” + “string” or StringBuilder? [duplicate]

蓝咒 提交于 2019-11-29 05:37:44
Possible Duplicates: Is String.Format as efficient as StringBuilder C# String output: format or concat? What is the performance priority and what should be the conditions to prefer each of the following: String.Format("{0}, {1}", city, state); or city + ", " + state; or StringBuilder sb = new StringBuilder(); sb.Append(city); sb.Append(", "); sb.Append(state); sb.ToString(); Compiler will optimize as much string concat as it can, so for example strings that are just broken up for line break purposes can usually be optimized into a single string literal. Concatenation with variables will get

Is python += string concatenation bad practice?

帅比萌擦擦* 提交于 2019-11-29 05:27:20
I am reading The Hitchhiker’s Guide to Python and there is a short code snippet foo = 'foo' bar = 'bar' foobar = foo + bar # This is good foo += 'ooo' # This is bad, instead you should do: foo = ''.join([foo, 'ooo']) The author pointed out that ''.join() is not always faster than + , so he is not against using + for string concatenation. But why is foo += 'ooo' bad practice whereas foobar=foo+bar is considered good? is foo += bar good? is foo = foo + 'ooo' good? Before this code snippet, the author wrote: One final thing to mention about strings is that using join() is not always best. In the

Is string concatenation in scala as costly as it is in Java?

雨燕双飞 提交于 2019-11-29 04:34:28
问题 In Java, it's a common best practice to do string concatenation with StringBuilder due to the poor performance of appending strings using the + operator. Is the same practice recommended for Scala or has the language improved on how java performs its string concatenation? 回答1: Scala uses Java strings ( java.lang.String ), so its string concatenation is the same as Java's: the same thing is taking place in both. (The runtime is the same, after all.) There is a special StringBuilder class in