如何在数字之间添加空格,使用DisplayFormat
如何在数字之间添加空格DisplayFormat。如何在数字之间添加空格,使用DisplayFormat
像这个例子:
50130301037855000150550010000000131000000132
我需要这样的:
5013 0301 0378 5500 0150 5500 1000 0000 1310 0000 0132
人有一个想法?谢谢。
我发现使用DisplayFormat
9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999;0;
感谢所有的答案。
您不能像使用DisplayFormat属性那样格式化,但可以依赖OnGetText事件来实现此目的。
我假设你的领域是字符串类型,例如:
function InsertBlankEach4Chars(S: string): string;
begin
Result := '';
while S <> '' do
begin
Result := Result + Copy(S, 1, 4) + ' ';
Delete(S, 1, 4);
end;
Result := Trim(Result);
end;
procedure TMyForm.MyQueryFieldGetText(Sender: TField;
var Text: string; DisplayText: Boolean);
begin
if DisplayText then
Text := InsertBlankEach4Chars(Sender.AsString)
else
Text := Sender.AsString;
end;
免责声明:此代码写在浏览器中,并没有进行测试。如果你打算在时间敏感的过程中使用它,我警告你可以优化这个函数以获得更好的性能。
这不是如何使用''标签,但我不能争辩结果...... – 2013-03-26 21:08:19
注意:如果字段类型是整型或largeInt,则可以使用DisplayText属性。只要将它设置为'0000 0000 0000 0000 ...'。 – alzaimar 2013-03-26 21:11:42
我认为这是最好的解决方案。 – 2013-03-27 07:20:29
你使用什么数据类型? – jachguate 2013-03-27 00:31:06
我正在使用一个字符串。 – dataol 2013-03-27 00:46:00