在 Delphi /Lazarus Pascal中有没有一个相当于C#的字符串插值的东西?我知道Oxygene有它,它支持.Net框架?

omhiaaxx  于 2023-01-05  发布在  C#
关注(0)|答案(1)|浏览(161)

Delphi /Object Pascal中是否有C#字符串插值的等价物?我知道有几个Object Pascal变体,如REMObjects Oxygene和PascalABC.Net,它们都有字符串插值功能,但都是基于CLI/. Net框架的语言?
C#字符串插值示例:

double a = 3;
double b = 4;
Console.WriteLine($"Area of {a} and {b} is {0.5 * a * b}");
bwntbbo3

bwntbbo31#

不, Delphi 或FreePascal中没有类似C# string interpolation的东西,最接近的等价物是SysUtils.Format(),例如:

uses
  ..., SysUtils;

var
  a, b: Double;
begin
  a := 3.0;
  b := 4.0;
  WriteLn(Format('Area of %f and %f is %f', [a, b, 0.5 * a * b]));
  ...
end;

相关问题