Logo

Programming-Idioms

  • Python
  • Pascal
  • Go

Idiom #153 Concatenate string with integer

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

import "fmt"
t := fmt.Sprintf("%s%d", s, i)
import "strconv"
t := s + strconv.Itoa(i)

This is faster than fmt.Sprintf.
t = '{}{}'.format(s, i)
t = '%s%s' % (s, i)
t = s + str(i)
t = f"{s}{i}"

The f in front of the string makes it a Literal String, in which you can put expressions inside brackets
uses SysUtils;
t := s + IntToStr(i);
uses Sysutils;
t := s + i.ToString;
t : String := s & Integer'Image (i);

New implementation...
< >
programming-idioms.org