This language bar is your friend. Select your favorite languages!

Idiom #153 Concatenate string with integer

Create string t as the concatenation of string s and integer i.

t : String := s & Integer'Image (i);
#include <string>
auto t = s + std::to_string (i);
var num = 1;
var str = "str";
var x = $"{str}{num}";
import std.conv : to;
string t = s ~ to!string(i);
import std.format : format;
string t = "%s%d".format(s, i);
write (unit=t,fmt='(A,I0)') s, i
import "fmt"
t := fmt.Sprintf("%s%d", s, i)
t = s ++ show i
let t = s + i
{
  // Using template literals:
  let t = `${s}${i}`
}
String t = s + i;
(format nil "~a~a" s i)
$t = $s . $i;
SysUtils
begin
  t := s + IntToStr(i);
end.
uses Sysutils;
t := s + i.ToString;
my $t = "$s$i";
my $t = $s . $i;
t = '{}{}'.format(s,i)
t = s + i.to_s
let t = format!("{}{}", s, i);
val t = s + i

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org

Related idioms