字符串填充和对齐

Strings paddings and alignments

我今天尝试使用 TextIo 保存文件。仅 3 行:

Radio Station;MagicFM
Test;This is jost for testing purpose.
TV;TV_Brand

一切都很好,但后来我读了它。

我无法对齐这些东西。

可能是这样的:

Radio Station         - MagicFM
Test                  - This is jost for testing purpose.
TV                    - TV_Brand

这是我的代码:

info(strFmt("%1  - %2", strLFix( conPeek(con, 1), 20),conpeek(con, 2)));

我玩过一些 strRFix 和 strLFix,但运气不好..有没有简单的方法来完成这个?

您必须像 Courier 一样使用 Fixed width font。可变宽度字体无法在视觉上对齐。

像这样对齐输出不是 infolog 的预期用途,正如 Matej 所说,原因是字体。但是,如果您希望将信息日志用于显示目的,您可能希望像这样使用它以获得以下输出:

static void Job114(Args _args)
{
    container       c, cc;
    int             i;

    c = [["Radio Station", "MagicFM"], ["Test", "This is jost for testing purpose."], ["TV", "TV_Brand"]];
    setPrefix("Output"); // SetPrefix is necessary to get the tabbing to function correctly
    for (i=1; i<=conLen(c); i++)
    {
        cc = conPeek(c, i);
        info(strFmt("%1\t%2", conPeek(cc, 1), conPeek(cc, 2)));
    }
}

您可以尝试使用 System.String.Format 方法,例如:

str       s; 
s = System.String::Format("{0, -15} - {1, -15}", "Radio Station", "MagicFM");    
info(s);

有关详细信息,请参阅 Align String with Spaces, strFmt Function [AX 2012] and String.Format Method