I want to concatenate string and int. But it doesn't work with & and add operator.
echo "abc" & 2
But it doesn't work.
To concatenate a string to an int value, use the concatenation operator. Here is our int. int val = 3; Now, to concatenate a string, you need to declare a string and use the + operator.
To concatenate string and integer data, we have to convert integer to string at first. To convert it we are using stringstream.
Concatenation using += operator. The following example concatenates using the += operator. DECLARE @v1 VARCHAR(40); SET @v1 = 'This is the original. '; SET @v1 += ' More text.
There's an operator $
that converts something to string.
echo "abc" & $2
echo "abc", 2 # echo automatically applies `$` to its arguments
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With