简体   繁体   English

Delphi/Lazarus Pascal 中是否有等效于 C# 的字符串插值? 我知道 Oxygene 有它支持 .Net 框架吗?

[英]Is there an equivalent to C#'s string interpolation in Delphi/Lazarus Pascal? I know Oxygene has it which supports the .Net framework?

Example of C# String Interpolation: To use interpolation in strings, put the name of the relevant variable between brackets {} and put a dollar sign $ in front of the string. C# 字符串插值示例: 要在字符串中使用插值,请将相关变量的名称放在方括号 {} 之间,并在字符串前面放一个美元符号 $。 This will tell C# to use interpolation.这将告诉 C# 使用插值。

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

'''



No, there is nothing like C# string interpolation in Delphi or FreePascal.不,Delphi 或 FreePascal 中没有像C# 字符串插值那样的东西。 The closest equivalent is SysUtils.Format() , eg:最接近的等价物是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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM