string - 如何从 LCDHype 中的插件返回空格?
问题描述
我使用 Delphi 为 LCDHype 编写了一个插件,我想返回一个包含空格的字符串。这是一个例子:
...
implementation
...
var
gReturnValue: String;
// Plugin.Foo.GetBar
function Library_GetBar(const AParameter: PScriptFunctionImplementationParameter): PWideChar; stdcall;
begin
gReturnValue := 'This is a bar';
result := PWideChar(gReturnValue);
end;
这些空格被应用程序以某种方式从字符串中删除,并且永远不会显示。
我该如何解决这个问题?
披露:我是 LCDHype 的作者
解决方案
插件的返回值由 LCDHype 解析,这意味着返回值基本上是脚本代码。
这也意味着当您想要保留空格时必须返回一个字符串。字符串'
以类似的字符开始和结束
'This is a bar'
在 Delphi 中,您需要转义'
字符,因此值将是
'''This is a bar'''
您可以使用QuotedStr()
转义'
字符并正确引用字符串,例如:
uses SysUtils; // for QuotedStr()
...
function Library_GetBar(const AParameter: PScriptFunctionImplementationParameter): PWideChar; stdcall;
begin
gReturnValue := QuotedStr('This is a bar');
result := PWideChar(gReturnValue);
end;
推荐阅读
- javascript - 如何用vue制作自定义轮播动画?
- laravel - 在一个视图中显示多个图像 laravel 7
- github-api - 从 github 下载最新的 git/git 版本
- kubernetes - kubelet 重启后,节点状态始终为 Ready,SchedulingDisabled
- plc - 如何将变量类型作为参数传递给 IEC61131-3 结构化文本 (TwinCAT3) 中的函数?
- vb.net - 如何修复 Visual Basic 2019 的溢出异常
- ag-grid - 如何修改或删除列的最大宽度?
- javascript - 如何修复错误不使用被动侦听器来提高滚动性能(灯塔报告)
- jenkins - jenkins 中的 SSH 自动化
- asp.net - 如何使用 ASP.NET Core 在数据库中插入当前登录的用户