Logo

Programming-Idioms

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

Idiom #302 String interpolation

Given the integer x = 8, assign to the string s the value "Our sun has 8 planets", where the number 8 was evaluated from x.

uses SysUtils;
s := 'Our sun has '+IntToStr(x)+' planets';
uses SysUtils;
s := Format('Our sun has %d planets',[x]);
uses SysUtils;
s := 'Our sun has '+x.ToString+' planets';
#include <stdio.h>
char s[32] = "";
sprintf(s, "Our sun has %i planets", x);

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