C#-style String interpolation

Does PascalABC.net support C#-style string interpolation? I know Delphi/Lazarus do not, but RemObjects Oxygene does support C#-style string interpolation. Thank you!

Gary Chike

I think you should try before asking. It’s literally the same syntax as in C#:

## $'You entered {ReadInteger} of integer type'.Print;
1 лайк

Сергей! Вы становитесь слишком высокомерным. На форуме и так почти никого не осталось, зачем же отпугивать таким тоном тех, кто сюда обращается с вежливыми вопросами, тем более иностранцев? Это не элитарный клуб для снобов. Никто вас не заставляет отвечать, если считаете, что вопрос для вас слишком банальный.

Thank you! That’s excellent that PascalABC supports string interpolation. I had originally copied code from Oxygene, but I forgot that PascalABC only supports single quotes and not double quotes which originally caused an error. :laughing:

Спасибо! Замечательно, что PascalABC поддерживает строковую интерполяцию. Изначально я скопировал код из Oxygene, но забыл, что PascalABC поддерживает только одинарные кавычки, а не двойные кавычки, которые изначально вызывали ошибку.

(Also, you need an empty line before ---, or whatever you use for <hr>, for it to work)

It’s working well with this simple test :+1:

program Oxygene_copy;

begin

    var fname: string;
    var age: integer;
    var gpa: real;

  write('What is your name? ');
  readLn(fname);
  writeLn('It''s nice to meet you ' + fname + '!');
  writeLn($'It''s nice to meet you {fname}!');
  write('How old are you? ');
  readLn(age);
  write('What is your GPA? ');
  readLn(gpa);
  writeLn('So you''re ' + age + ' years old and your GPA is ' + gpa + '.');
  writeLn($'So you''re {age} years old and your GPA is {gpa}.'); 

  writeLn($'The product 50 x 4 is: {50 * 40} '); 
  readLn

end. 

Why not? See PascalАВС.NЕТ code below:

##
var fname := ReadlnString('What is your name?');
Println('It''s nice to meet you ' + fname + '!');
Println($'It''s nice to meet you {fname}!');
var age := ReadInteger('How old are you?');
var gpa := ReadReal('What is your GPA?');
Println('So you''re ' + age + ' years old and your GPA is ' + gpa + '.');
Println($'So you''re {age} years old and your GPA is {gpa}.'); 
Println($'The product 50 x 4 is: {50 * 40}') 
1 лайк

I knew that PascalABC is capable of inline variable declarations which is somehwat similar to Oxygene’s syntax:

/* Oxygene syntax */
var fname := readLn();
var age := Int16.Parse(readLn());
var gpa := Double.Parse(readLn());

But PascalABC’s construct reminds me more of Basic or Python by which input is being received, assigned to a variable and output is occurring all at the same time which is very cool! I’m duly impressed. Thank you for sharing!

# Python syntax
fname = input("What is your name? ")
; Basic syntax
input "What is your name? "; fname$

Я знал, что PascalABC способен объявлять переменные в строке, что в некоторой степени похоже на синтаксис Oxygene:

Но конструкция PascalABC больше напоминает мне Basic или Python, где входные данные принимаются, присваиваются переменной и выводятся одновременно, что очень здорово! Я под впечатлением. Спасибо, что поделились!

Some of the syntactic constructs and ideas of PascalАВС.NЕТ have been taken from C#, Oxygene, Haskell, and Python. Therefore, it turned out to be much more powerful than Oxygene.

Некоторые синтаксические конструкции и идеи PascalАВС.NЕТ были взяты из C#, Oxygene, Haskell и Python. Поэтому он оказался намного мощнее Oxygene.

P.S. No problem for “strange”:

var gpa := Double.Parse(ReadlnString('What is your GPA?'));

1 лайк